Question

How do I add 23 hrs 59 min. 59 secs to end_date?

var end_date = jQuery('#end_date_datepicker').datepicker('getDate');
//pseudo-code:  end_date = (end_date + 23:59:59) 

I was thinking of trying to convert it to milliseconds, add 86 399 000 milliseconds, and then convert it back to time. But, I can't get it to work.

Was it helpful?

Solution

The getDate method returns a JavaScript Date object so just add one day and remove one second:

var end_date = jQuery('#end_date_datepicker').datepicker('getDate');
end_date.setDate(end_date.getDate() + 1);
end_date.setSeconds(end_date.getSeconds() - 1);

The Date object will take care of adjusting everything to maintain a valid date. You could also manipulate the hours, minutes, and seconds on their own if you wanted.

OTHER TIPS

There might be better way, but you do new Date(end_date.UTC() + 86399000)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top