2

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Laxmidi
  • 2,650
  • 12
  • 49
  • 81

2 Answers2

6

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
1

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

ComfortablyNumb
  • 3,391
  • 2
  • 14
  • 15