php - STR_TO_DATE MySQL swaps Month/Day values -
php - STR_TO_DATE MySQL swaps Month/Day values -
gd all,
when using php insert info mysql database pass values using post method script.
using str_to_date function in effort proper date inserted date field in mysql
however, despite using same format pass str_to_date function (dtereportdate=14-10-2014) mysql function apparently swaps month , day values when monthvalue <= 12 ?
so, if input 14-10-2014 import php correctly reads in table 2014-10-14 if input 09-10-2014 in same routine inserted in table 2014-09-10 ??
how can right in php script or anywhere else ?
i've tried several options: -changing input str_to_date function in avriety of formats (yyyy/mm/dd, dd-mm-yyyy etc.etc. error stays same -changing input info string straight input: i.e. instead of using
insert tbl ('date') values (str_to_date(datestring,'%y/%m/%d')
you utilize
insert tbl ('date') values (datestring)
where datestring correctly formatted "yyyy-mm-dd" per mysql default. (doesn't work either)
so how script input string correctly translated date format in mysql ??
much appreciated
accepted date format in sql database y-m-d
(you'll find different date format php date).
if info submitted form:
$date=date('y-m-d',strtotime($_post["date"]));
if date want insert today , static:
$date=date('y-m-d');
and query go this:
insert tbl ('date') values ('$date')
php mysql date
Comments
Post a Comment