www.webdeveloper.com
Results 1 to 8 of 8

Thread: Split and rearranging Date

  1. #1
    Join Date
    Jul 2008
    Posts
    30

    Split and rearranging Date

    Hey there,

    I am currently trying to split a date i'm getting and rearrange it.
    At the moment the date is shown like this in my html:

    dd-mm-yyyy

    but I need to rearrange it to

    yyyy/mm/dd

    to be able to use it and get more information from my json file, does anyone know how to do this?

    Thanks in advance,
    Bey

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    This works...

    Code:
    var $date = '15-09-2001';
    alert($date);
    $date = $date.replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1');
    alert($date);
    Last edited by Kor; 01-05-2011 at 10:04 AM.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by thraddash View Post
    This works...

    Code:
    var $date = '15-09-2001';
    alert($date);
    $date = $date.replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1');
    alert($date);
    Neat. Except that you should have explain to Bey a little bit more about RegExp. You gave him the fish, ok, but you should have given him the rod, as well

    Bey: more about Regular Expression in JavaScript:
    http://lawrence.ecorp.net/inet/samples/regexp-intro.php

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Quote Originally Posted by Kor View Post
    Neat. Except that you should have explain to Bey a little bit more about RegExp. You gave him the fish, ok, but you should have given him the rod, as well
    LOL! I was going to say the same thing. The rod and some fishing lessons.

    ^_^

  5. #5
    Join Date
    Aug 2009
    Posts
    593
    Ah, yes. The whole "Teach a man to fish" routine. My Appologies.

  6. #6
    Join Date
    Aug 2009
    Posts
    28
    I would like to know more about this technique as well, if someone would please indulge those of us who are ignorant on this.

  7. #7
    Join Date
    Jul 2008
    Posts
    30
    Thanks for both the fish and the rod! now I can practise, the link you gave me is a good guide.

  8. #8
    Join Date
    Aug 2009
    Posts
    28
    Oops! Missed that link. Sorry, ignore my last post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles