Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change date from MM/DD/YYYY to YYYY-MM-DD

    Hi

    I have a variable date in the format of 'OCT/18/2013' which i need to convert to '2013-10-18' so that i can pass it to an SQL query in my code in order to query the DB.

    The code i have at the minute is:

    function buildIntradayQuery($participant, $grantID, $grantType, $grantDate, $expireDate, $env){

    try{

    var $PRTC_ID = "'" + $participant +"'";
    var $GRANT_T = "'" + $grantType +"'";
    var $GRANT_ID = "'" + $grantID +"'";
    var $GRANT_D = "'" + $grantDate +"'";
    var $EXPIRE_D = "'" + $expireDate +"'";
    var $TABLE;

    if($env == "Shared") {
    $TABLE = "table4";
    } else if ($env == "Alpha") {
    $TABLE = "table4";
    }

    var $selectSQL = "select * from " + $TABLE + " WHERE SUB_PRODUCT_TY_C = " + $GRANT_T + " and PRODUCT_ID = " + $GRANT_ID + " and GRANT_D = " + $GRANT_D + " and EXP_D = " + $EXPIRE_D + " and PRTC_ID = " + $PRTC_ID;

    _log($selectSQL,"CUSTOM5");

    return $selectSQL;


    Where the variables are passed to this function from another function

    Any suggestions on how i can simply convert the date would be great

    thanks
    Seán

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,879
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    What is this? Java? C#?
    It’s not JavaScript, that I know.

  • #3
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its a form of Java Scripting used with automation tool Sahi.

    So its not valid to seek advice on this particular issue?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by seanog1888 View Post
    Its a form of Java Scripting used with automation tool Sahi.

    So its not valid to seek advice on this particular issue?
    I don't think many people here have experience of Sahi. Something like this?

    Code:
    var $grantDate = "OCT/18/2013";
    var mths = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
    var parts = $grantDate.split("/");
    var m = parts[0];
    for ( var i = 0; i < mths.length; i++ )    {
    if (mths[i] == m ) { 
    var mth = i;
    }
    }
    
    $grantDate = parts[2] + "-" + (mth+1) + "-" + parts[1];
    alert ($grantDate);  // for testing
    var $GRANT_D = "'" + $grantDate +"'";
    Last edited by Philip M; 06-26-2014 at 12:09 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help Philip i will give it a try and see how it works out.

    Yeah not many people seem to have much experience with Sahi, i will continue the struggle

    Thanks and Regards
    Seán

  • #6
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Philip

    That worked great with a few minor tweeks for Sahi.

    I just have one question, why is the +1 added to the math variable?

    (mth+1)

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,446
    Thanks
    13
    Thanked 361 Times in 357 Posts
    because JavaScript month numbers start at 0.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •