Need help for this date convertion

Hi, can i ask some help how would i convert this date

Wed May 07 13:39:36 CST 2014

into 2014-05-07 13:39:36

Is this possible?

Thank you in advance.

Try this:


echo '<br /><br />';
  echo '<b>Supplied: </b>' .$mystring = "Wed May 07 13:39:36 CST 2014";


echo '<br /><br />';
  date_default_timezone_set('GMT');
  echo '<b>Converted: </b>' .date('Y-m-d  H:i:s  - e ', strtotime($mystring));


echo '<br /><br />';
  date_default_timezone_set('Canada/Saskatchewan');
  echo '<b>Converted: </b>' .date('Y-m-d  H:i:s e', strtotime($mystring));


echo '<br /><br />';
  echo '<b>References: </b>http://php.net/manual/en/function.date.php';



Output:

Supplied: Wed May 07 13:39:36 CST 2014

Converted: 2014-05-07 19:39:36 - GMT

Converted: 2014-05-07 13:39:36 Canada/Saskatchewan

References: http://php.net/manual/en/function.date.php

PHP’s DateTime class can do the conversion for you.

Edit: John is feeling generous today and has given you a complete answer :wink:

Thank you so much for this :slight_smile:

Thank you fretburner :slight_smile:

[ot] And many thanks to you jemz, there are far too many posters who do not acknowledge and respond to the time it takes to answer a query.

The difficulty I had was not appreciating that the time zone is essential for a correct conversion.

I also learnt something new today :slight_smile:

[/ot]