i’ve got a date-range picker, with 2 field each date picker: dat_start and date_end;
everything’s fine except the Timestamp of the field I will pass to server to do the search; I know JS Timestamp is in ms, but I should have it /1000…and I can’t find the way to do. Here’s my code:
<script>
$(function () {
$("#data_inizio").datepicker({
altField: '#mod_available_date_id_start',
altFormat: '@',
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function (selectedDate) {
$("#data_fine").datepicker("option", "minDate", selectedDate);
}
});
$("#data_fine").datepicker({
altField: '#mod_available_date_id_finish',
altFormat: '@',
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function (selectedDate) {
$("#data_inizio").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>
Thanks to everyone, and sorry for my bad english!
Get the string/date selected by the picker and cast it to a date:
Now get the
valueOf()(which returns milliseconds since January 1, 1970) and divide by 1000 to get the number of seconds since [same].Example fiddle: http://jsfiddle.net/QpQ7U/
To have this happen on date selection, modify the
onSelectcallback function in the datepicker options.Example fiddle with onSelect: http://jsfiddle.net/QpQ7U/1/
To store the value in a hidden field, simply specify the field in the
onSelect:Example fiddle with hidden fields: http://jsfiddle.net/QpQ7U/2/
To format as day/month/year, use the
dateFormatoption:Example fiddle: http://jsfiddle.net/QpQ7U/5/