What is the correct format to pass to the date() function in PHP if I want to insert the result into a MySQL datetime type column?
I’ve been trying date('Y-M-D G:i:s') but that just inserts "0000-00-00 00:00:00" everytime.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that you’re using
'M'and'D', which are a textual representations, MySQL is expecting a numeric representation of the format2010-02-06 19:30:13Try:
date('Y-m-d H:i:s')which uses the numeric equivalents.edit: switched
GtoH, though it may not have impact, you probably want to use 24-hour format with leading 0s.