Convert data from email header

Can anyone help me how to convert data from email header?

I have the following date format from the email header: Wed, 28 Apr 2010 21:59:49 -0400

I need to convert them to mysql Date or timestamp. Thanks!

+6
source share
1 answer

You should use DateTime for this, in particular DateTime::createFromFormat() :

 $str = 'Wed, 28 Apr 2010 21:59:49 -0400'; $date = DateTime::createFromFormat( 'D, d MYH:i:s O', $str); 

Now you have a Date object in $date , and you can grab the unix timestamp (if that's what you want), or you can format it to a date for MySQL.

 echo $date->getTimestamp(); // Outputs: 1272506389 echo $date->format( 'Ymd H:i:s'); // For MySQL column, 2010-04-28 21:59:49 

You can see how it works in the demo .

+14
source

Source: https://habr.com/ru/post/921852/


All Articles