Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert data from email header

Does anyone could help me how to convert data from email header?

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

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

like image 876
d7p4x Avatar asked Aug 01 '12 13:08

d7p4x


People also ask

How do I extract email headers in Outlook?

Double-click an email message to open it outside of the Reading Pane. Click File > Properties. Header information appears in the Internet headers box.

How do I export an Outlook email header to Excel?

Just select the emails, press ctrl+c, then paste in Excel. Was this reply helpful? Was this reply helpful? Simply use the Outlook export function and select which fields you want included in the export.

How do I get meta data from an email?

Once you have an email message open in Gmail, click on the three-dot icon in the top-right hand corner of the message to expand the More menu. Click on Show original to see the raw email message with its full contents and header revealed.


1 Answers

You should be using DateTime for this, specifically DateTime::createFromFormat():

$str = 'Wed, 28 Apr 2010 21:59:49 -0400';
$date = DateTime::createFromFormat( 'D, d M Y H: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 into a date for MySQL.

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

You can see it working in the demo.

like image 111
nickb Avatar answered Sep 23 '22 02:09

nickb