Forum Moderators: coopster

Message Too Old, No Replies

Need to change order of datetime

From DD-MM-YYYY HH:MM:SS to YYYY-MM-DD HH:MM:SS

         

The Cricketer

9:22 am on May 20, 2005 (gmt 0)

10+ Year Member



Hi I have a problem.
I have an HTML form field into which is inserted a date and time in the following European format
21-02-2005 14:07:55
I am trying to insert this datetime into my Mysql database but I cannot get it into the following format before I insert it.
2005-02-21 14:07:55

I just need to know what the way to do this is?
Many thanks.

buriedUnderGround

10:00 am on May 20, 2005 (gmt 0)

10+ Year Member



try using substr() to create variables from your original date (ie; $day, $year, $month, $hour, etc) then rearrange those variables to make your new date.

The Cricketer

1:25 pm on May 20, 2005 (gmt 0)

10+ Year Member



Great thanks. I did something like

$day = substr($drawdatetime,0,2);
$month = substr($drawdatetime,3,2);
$year = substr($drawdatetime,6,4);
$time = substr($drawdatetime,11,8);
$drawdatetime = $year."-".$month."-".$day." ".$time;

ergophobe

8:32 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This should do it:

$date = date [php.net]("%Y-%m-%d %H:%i:%s", strtotime [php.net](21-02-2005 14:07:55 ));