Chris78 Chris78 - 3 months ago 8
MySQL Question

Need to reformat date variable to match date function in mysql

I have searched high and low on how to do this.

I am using the following datepicker script.

http://jqueryui.com/datepicker/


Unfortunately it formats the date like so
xx/xx/xxxx
. However, the
date
function in mysql saves the date like so
xxxx-xx-xx
. I used
str_replace
to replace the
/
to
-
. My deli-ma is trying to figure out now how to convert my variable
$editsentdate
from
xx-xx-xxxx
to the mysql
date
format
xxxx-xx-xx
. When I just send the variable to my DB like it is it stores it as
0000-00-00
which I am sure is b/c that it is not formatted by
Ymd
. Any help would be appreciated.

$editsentdate = str_replace('/','-',$_POST['edit_sent_date']); // xx-xx-xxxx

Answer

Use PHP's function date(). Example: date("Y-m-d", strtotime($_POST['edit_sent_date']))