Results 1 to 3 of 3

Thread: Format the date

  1. #1

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    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 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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 FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    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
  •  



Click Here to Expand Forum to Full Width