I have a date range picker on my website.
When a user inputs the date and time range, I want to send separately within the form the startDate
and the endDate
daterangepicker code:
$('input[name="datetimes"]').daterangepicker({
timePicker: true,
timePickerIncrement: 5,
startDate: moment().startOf('hour'),
endDate: moment().startOf('hour').add(32, 'hour'),
locale: {
format: 'YYYY-MM-DD hh:mm'
},
opens: 'center',
drops: 'auto'
});
And this is what I tried:
$('#formid').submit(function(e) {
e.preventDefault();
let startDate = ($('#datetimes').data('daterangepicker').startDate).format('YYYY-MM-DD hh:mm');
let endDate = ($('#datetimes').data('daterangepicker').endDate).format('YYYY-MM-DD hh:mm');
$(this).append('<input type="hidden" name="start_date" value='+startDate+' /> ');
$(this).append('<input type="hidden" name="end_date" value='+endDate+' /> ');
this.submit();
});
Before the this.submit();
I did a console.log(startDate)
and thi is what I am getting:
I am getting the date and the time (as expected), but then if I try doing a print(request.POST)
in the view (django back-end), this is what I get:
Somehow, during the POST
the HH:mm
disappeared.
How can I keep the values of hh:mm
during the POST?