Trying to convert a date & time value in the format of “07/19/2011 00:00” using the php function “strtotime()”.
Doesn’t seem to like the structure of the date time. Does anyone know how I can convert this to a timestamp for MySQL database?
$convertstart = strtotime($_POST['start']);
$start = mysql_real_escape_string($convertstart);
$convertend = strtotime($_POST['end']);
$end = mysql_real_escape_string($convertend);
Thanks!
EDIT also…
When I convert today’s date( 07/31/2011 18:35 ) I get back 2013-12-15 17:00:00 in the MySQL
Why not let MySQL take care of it for you. Try out MySQL’s
STR_TO_DATE()function. It uses the same format specifiers as theDATE_FORMAT()function.Try this:
SELECT STR_TO_DATE('07/31/2011 18:35', '%m/%d/%Y %H:%i');It should give you a time-stamp compatible with MySQL DATETIME fields. For me it returns:
2011-07-31 18:35:00