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
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Oracle timestamp date conversion to Javascript

    Hi peers,,

    i am passing oracle time stamp dates to javascript array element.
    the problem is i am unable to convert them to standard format :

    here is the date format i am getting from Oracle to javascript array :

    {ts '2011-03-15 00:00:00'}

    and here is what i want to get : 03/15/2011


    Any help ?

    thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Ummm...standard JavaScript form for creating a Date is this:
    Code:
    var mydate = new Date( 2011, 3, 15 );
    No place in JavaScript would you ordinarily want to pass in "03/15/2011". It works in some browsers in some circumstances, but it's not the best idea.

    You don't say what server-side technology you are using (PHP? ASP? JSP?) but whichever one it is, the best thing to do is to use coding to convert the Oracle date (however it appears in the server-side language) into the form above.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Hi OIld PEdant ,

    I am using Coldfusion serv Side language .

    but what i am dong for soem reason is the following :

    i am loading oracle field data into javascript array

    then assign the javascript element date value to form filed values ..

    That is why i van not do it at form field level ..

    thoughts ?

    thanks

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    So you *want* it to appear in the HTML page as something like
    Code:
    <input name="startDate" value="03/15/2011" />
    ??

    In that case, yes, just dump it into the JS array as
    Code:
    var dates = [ "03/15/2011", "05/22/2011", "11/02/2011" ];
    or whatever. CF should give you a way to do that.

    But if it doesn't, if the only thing you can figure out how to do is create
    Code:
    var dates = ['2011-03-15 00:00:00', '2011-05-22 00:00:00', '2011-11-02 00:00:00'];
    then it would be easy enough to ask JS to convert those to mm/dd/yyyy for you.

    example:
    Code:
    var temp = dates[0].replace(/\s/g,"-").split("-");
    var mmddyyyy = temp[1] + "/" + temp[2] + "/" + temp[0];
    document.formName.startDate.value = mmddyyyy;
    But I'd really try to figure out how to get CF to do that for you. It can't be that hard.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    korssane (09-07-2011)

  • #5
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Hi Old PEdant,


    Cf can do it using the DAteFormat(myDate, "mm/dd/yyyy") but for some reasons it did not work..

    thanks

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    As a *guess*, I'd say maybe CF isn't recognizing the value it is getting from Oracle as a valid Date to begin with, so then it can't format what it doesn't think is a date.

    Pure guess.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Hi Old PEdenat ,

    i have fixed it ..than kyou for redirecting me..there wa a mising " cotation

    thanks gain and sorry for bothering ?


  •  

    Posting Permissions

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