Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for ex 2014-12-13T20:00:00Z to 2014-12-14T21:00:00Z
In an Date get error invalid date

JavaScript
var strArray = listItemFromAndToDate.split(' , ');
        var dateAndTimeFrom = strArray[0];
        var dateAndTimeTo = strArray[1];

        var fromArray = dateAndTimeFrom.split(' ');
        var toArray = dateAndTimeTo.split(' ');

        var fromdate = fromArray[0]; // year month day
        var fromtime = fromArray[1]; // hours minutes
        var toDate = toArray[0];  // yearsto monthto dayto
        var totime = toArray[1]; // hoursto hoursfrom


        var resultnew = fromdate + "T" + fromtime + ":00" + "Z";
        var result2New = toDate + "T" + totime + ":00" + "Z";
        var fromTimenew = new Date(resultnew);
        var toTimenew = new Date(result2New);

JavaScript
bookedFreeTimes.push(year + "-" + month + "-" + day + " " + hours + ":" + minutes + " , " + yearto + "-" + monthto + "-" + dayto + " " + hoursto + ":" + minutesto);

here is my string that i splitting my resultnew and result2new get as in the string in the top, but when trying to add new date to them i get invalid date?

But another place i have 2 datepicker were i select date and time to and from.
Java
var listItemCustom = document.getElementById('datepicker').value;
        var listItemFromTime = document.getElementById('timepicker').value;
        var listItemtoDate = document.getElementById('datepickerto').value;
        var listItemToTime = document.getElementById('timepickerTo').value;
       
        var result = listItemCustom + "T" + listItemFromTime + ":00" + "Z";
        var result2 = listItemtoDate + "T" + listItemToTime + ":00" + "Z";
        var fromTime = new Date(result);
        var toTime = new Date(result2);


Like this works, i dont get invalid date here , and the string are displayed the same.
Posted
Updated 6-Dec-14 3:51am
v3
Comments
Kornfeld Eliyahu Peter 7-Dec-14 3:39am    
Check the value from the datetime picker - it may have a different order of year-month-date...

1 solution

hi,

check your datepicker value,what they return

if they return date with time or other date format you can change it to desire date format

$("#datepicker").datepicker("option", "dateFormat", "yyyy-mm-dd");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900