When I set a date with native JS tools, with an ISO date as the input, the date that I obtain is: Wed Apr 29 2020 02:00:00 GMT+0200
, so the hour is 2 p.m.
When I set a date using jQuery UI datepicker with the code below, I end up with: Wed Apr 01 2020 00:00:00 GMT+0200
and Wed Apr 29 2020 00:00:00 GMT+0200
, so the hour is 0 p.m.
I need to compare date
to date_min
and date_max
, and this difference with the hours doesn't help.
Apparently the 2 p.m. from the first method is time zone dependant. What is the best way to make my dates easily comparable?
Thank you for your time!
<script>
var date = new Date('2020-04-29');
var date_min, date_max;
$(function() {
$('#from').datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function() {
date_min = $(this).datepicker('getDate');
date_max = $('#to').datepicker('getDate');
if (date && date_min && date_max)
console.log(date, date_min, date_max, date.getTime(), date_min.getTime(), date_max.getTime());
}
});
$('#to').datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function() {
date_min = $('#from').datepicker('getDate');
date_max = $(this).datepicker('getDate');
if (date && date_min && date_max)
console.log(date, date_min, date_max, date.getTime(), date_min.getTime(), date_max.getTime());
}
});
});
</script>
<div id="date">
<label for="from">from</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
</div>