SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dd/mm/yy to mm/dd/yy

    Hi friends!
    Is there any way to change dd/mm/yy to mm/dd/yy using javascript?
    I get dd/mm/yy from something like document.form.text.value.

    Any idea???

  2. #2
    Non-Member
    Join Date
    Aug 2002
    Location
    USA
    Posts
    544
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably explode it then reassemble.

  3. #3
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you could use String.split() to break the entry at the /'s and the reassemble the resulting array according to your needs. Something like (off the cuff, no testing):
    var orig_str=document.form.text.value;
    var spl_str=orig_str.split("/");
    var new_str=spl_str[1]+"/"+spl_str[0]+"/"+spl_str[2];

    If you convert to an actual Date object, other means are available.

  4. #4
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    Perhaps you could use String.split() to break the entry at the /'s and the reassemble the resulting array according to your needs. Something like (off the cuff, no testing):
    var orig_str=document.form.text.value;
    var spl_str=orig_str.split("/");
    var new_str=spl_str[1]+"/"+spl_str[0]+"/"+spl_str[2];

    If you convert to an actual Date object, other means are available.
    Thanks for your idea PAS. I tried the easier way though (basically the same logic I suppose). Copy pasting JVLB's code is working perfectly - I wasted all my evening yesterday thinking out a solution. Thanks you very much all.
    Wish you guys a nice weekend.


Bookmarks

Posting Permissions

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