php - Store a user-input date string as datetime -
i'm using php, , need parse date string formatted dd/mm/yyyy
, store in mysql.
how can convert string datetime variable in mysql table?
probably best way using this: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
select str_to_date('04/31/2004', '%m/%d/%y'); -> '2004-04-31'
or equivalent php functions like: http://www.php.net/manual/en/function.date-parse-from-format.php (from php 5.3)
a generic php function like
function convertdate($datestring) { return date('y-m-d h:i:s',strtotime(str_replace('/','-',$datestring))); }
or
function convertdate($datestring) { $a = explode($datestring('/')); return "{$a[2]}-{$a[1]}-{$a[0]} 00:00:00"; }
Comments
Post a Comment