I have the below datepciker:
<script>
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: 'mm-dd-YYYY'
}).val(getTodaysDate(0)); // For current date
});
function getTodaysDate (val) {
var t = new Date, day, month, year = t.getFullYear();
if (t.getDate() < 10) {
day = "0" + t.getDate();
}
else {
day = t.getDate();
}
if ((t.getMonth() + 1) < 10) {
month = "0" + (t.getMonth() + 1 - val);
}
else {
month = t.getMonth() + 1 - val;
}
return (day + '/' + month + '/' + year);
}
</script>
The input:
<input type="text" id="datepicker" name="datepicker">
And here I'm trying to insert the date to my MySQL db. There is no error message, the insert command runs OK, but the date field in my db is empty/NULL.
$date = $_POST['datepicker'];
$sql="INSERT INTO table (dt) VALUES ('$date')";
Is this some value type issue or what? The dt
column in my db is DATE
.
*UPDATE @Dwza: So I modified the script:
dateFormat: 'YYYY-mm-dd'
and
return (year + '-' + month + '-' + day);
And the INSERT
suggested by the link you mentioned:
$parts = explode('-', $_POST['datepicker']);
$date = "$parts[2]-$parts[0]-$parts[1]";
$sql="INSERT INTO transfer (dt) VALUES ('$date')";
Still no go.
**SOLVED:
$date = "$parts[0]-$parts[1]-$parts[2]";