convert date data into mysql date format
17,010
Yes, you can convert the date with strtotime();
$dateToday = date("d-m-Y");
$newDate = date("Y-m-d", strtotime($dateToday));
OUTPUT: 2012-12-27
And then you can store data to your database.
When you have to recover the date you can reverse this operation like this:
$dateFromDatabase = "2012-12-27";
$reverseDate = date("d-m-Y", strtotime($dateFromDatabase));
OUTPUT: 27-12-2012
(corrected "Y-m-d" to "d-m-Y" in 2nd date call)
Author by
ramadani
Updated on June 16, 2022Comments
-
ramadani almost 2 years
I want to convert the data on which I have the format
$dateToday = date("d-m-Y");
so the value of $dateToday is 27-12-2012
Then I want to save it to the database with the mysql data type date. How to keep the value of 27-12-2012 it can be stored in the mysql database with the format 2012-12-27? Help me please. Thank you
-
ramadani over 11 yearsyes, that's work. thank you very much friends. it's very help me :)
-
Samiul about 9 yearsit will not work for if i input 04-03-2015 in US format