0

I want to convert the following date to Y-m-d but it does not work correctly

$date='Thu Jul 01 2021 15:22:00 GMT 0300 (Eastern European Summer Time)';
$from=date('Y-m-d',strtotime($date));

echo $from; displays 1970-01-01

chris227
  • 579
  • 9
  • 28
  • 1
    PHP/`strtotime` doesn't understand your format; more precisely the time zone information. First, it should be GMT+0300. Second, strotime doesn't know "Eastern European Summer Time", it only knows _EEST_. Third, redundant information. GMT+0300 is the same as EEST. Fourth, the parenthesis also throw off the parser. – maryisdead Jul 09 '21 at 13:29
  • date_default_timezone_set('EST'); $date='Thu Jul 01 2021 15:22:00 GMT +3:00'; echo $from=date('Y-m-d h:i:s',strtotime($date)); – Vishal P Gothi Jul 09 '21 at 14:33
  • @maryisdead that is the format i recieve it from $_GET – chris227 Jul 12 '21 at 07:23
  • @chris227 Can't help you with that. It remains invalid. :P If you know that it's coming in like that, you can easily fix it? Also, have a look at [`date_create_from_format`](https://www.php.net/manual/en/datetime.createfromformat.php). – maryisdead Jul 12 '21 at 15:55

0 Answers0