I have a PHP function that gets passed a date in the format MM/DD/YYYY
I need to then convert this so that it can be added to a MySQL field that is of type date
How would I go about doing this in PHP?
The following is the output. The following is the query to format the date to YYYY-MM-DD. mysql> select str_to_date(LoginDate,'%d. %m.
In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.
Change YYYY-MM-DD to DD-MM-YYYY$newDate = date("d-m-Y", strtotime($orgDate));
$newvalue = date('Y-m-d', strtotime($originalvalue));
MySQL displays the DATE type as 'YYYY-MM-DD',
so you could do something like:
date("Y-m-d",strtotime("10/18/2013"));
My variant:
$mysql_date = date('Y-m-d', strtotime(str_replace('/','-', $value)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With