Reputation: 155
I have this problem with saving a date into a MySQL database.
I have this input field:
<input type="date" name="theDate" id="theDate" required></p>
Before I save it to the database I format the string to a date like this:
date('Y.m.d', strtotime($table['day']));
The database field is a DATE but it only saves 0000-00-00
.
When I echo out the date before saving it, it is correctly 2012-02-23
.
I hope anyone can tell me how this is done.
Upvotes: 0
Views: 86
Reputation: 38147
date('Y.m.d', strtotime($table['day']));
outputs 2012.02.23
not 2012-02-23
... you need
date('Y-m-d', strtotime($table['day']));
See this section on MySQL Date and Time literals
Upvotes: 2