www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript date manipulation

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    Javascript date manipulation

    Hi,
    My knowlege of javascript is fairly limited and the following has got me stumped;

    I am using AspGrid, which has a datepicker. Once submitted the form calls a javacript function called validate, where I want it to obtain the date from the form calender and add 5 days to it and alert the new date in a popup message window. My code is as follows;

    <SCRIPT LANGUAGE="JavaScript">
    function Validate()
    {
    var myDate = new Date(Date.parse(document.AspGridFormSave1.FIELD4.value));
    myDate.SetDate(myDate.getDate()+5);
    alert(myDate)
    return true;
    }
    </SCRIPT>

    For some reason the above code does not work on gives the wrong date, which I think is down to date format (I am based in the UK - dd/mm/yyyy) and/or local versus UTC.

    Any help would be much appreciated as I have spent a lot of time on this!

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,265
    Parse your date manually and use the Date constructor new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]]), like explain on this page

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Thank you for the prompt reply. Sorry but your link to 'this page' did not work and my knowledge of javascript is fairly basic.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,265
    Sorry. Try this link : http://stackoverflow.com/questions/2...ipt-date-parse
    or Google date parse javascript

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