I would like to save the datepicker date to MySQL, as I can able to select the date format using the javascript. Even I tried logging to console the format looks fine as YYYY-MM-DD. Unfortunate, when INSERT query to MySQL the datepicker from the input type picks up today's date.
PackingDate: new Date().toISOString().slice(0, 19).replace('T', ' ')
i tried passing the req.PackingDate
Like PackingDate: req.PackingDate.toISOString().slice(0, 19).replace('T', ' ')
But nothing works as it keeps storing today's date.
ejs:
<input type="text" id="PackingDate" name="PackingDate"/>
javascript:
$(document).ready(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#PackingDate').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: 'yy-mm-dd'
});
});
.js:
PackingDate: new Date().toISOString().slice(0, 19).replace('T', ' ')