Results 1 to 3 of 3

Thread: Format the date

  1. #1
    Lively Member Yumby's Avatar
    Join Date
    Feb 09
    Posts
    105

    Format the date

    Hi all. I'm a javascript newbie and I'm stuck, so I've got some questions.

    The first one is, I know you can store the date like this....
    Code:
    var mydate = new Date(2000, 11, 31);
    But on the web page the person enters the date like this..... 31/12/2000. So is it possible to code it this way....
    Code:
    var mydate = new Date(31/12/2000);
    I couldn't find anything on the internet, so maybe someone can offer some tips or help? Thanks.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: Format the date

    You could try the datejs library. Link: http://code.google.com/p/datejs/

    It allows various parsing and formatting ways. Check the sample usage section for more details.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 07
    Posts
    365

    Re: Format the date

    Are you getting the date as one string? If so, you can split by the char '/' and have your date in an array.

    Code:
    var date = "31/12/2000";
    var date_array = date.split("/");
    
    var day = date_array[0];
    var month = date_array[1];
    var year = date_array[2];
    For more info: http://www.w3schools.com/jsref/jsref_split.asp

Posting Permissions

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