moisesbr Posted August 15, 2013 Share Posted August 15, 2013 Hi A date is expressed in character format as below: $date_course = "22/08/2013" ; # day/month/year I am trying to insert it in mysql table using: $date=date("Y-m-d",strtotime($date)); But I imagine is not enough and I have to convert it to "2012/08/22" before transforming it to date. Please help me to clarify this issue and solve it. Moises Quote Link to comment https://forums.phpfreaks.com/topic/281193-characters-to-date/ Share on other sites More sharing options...
Solution gristoi Posted August 15, 2013 Solution Share Posted August 15, 2013 you can use the datetime object in PHP: $date = DateTime::createFromFormat('d/m/Y', $date_course); $dateForDb = $date->format('Y-m-d'); hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/281193-characters-to-date/#findComment-1445125 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.