PHP Classes

Decode Date?

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Decode Date?  >  (Un) Subscribe thread alerts  
Subject:Decode Date?
Summary:Any suggestions how to decode different date formats?
Messages:4
Author:Petar
Date:2007-10-17 19:47:54
Update:2007-10-18 06:41:13
 

  1. Decode Date?   Reply   Report abuse  
Picture of Petar Petar - 2007-10-17 19:47:54
Hi,

I have some troubles decoding message daate formats. I reveive lots of messages with Date like "Date: Wed, 17 Oct 2007 12:45:19 UT"

Could you suggect me how to decode any different date formats?

Thanks.

  2. Re: Decode Date?   Reply   Report abuse  
Picture of Christophe Charron Christophe Charron - 2007-10-17 20:40:24 - In reply to message 1 from Petar
Hi,
what's the problem with this date ? It's a RFC-822 date time format !!
Here is the code I use

$vl_c_z04=$decoded[0]["Headers"]["date:"];
if (($timestamp = strtotime($vl_c_z04)) === false) {
if (strtolower(substr($vl_c_z04,-2))=="ut") {
$vl_c_z04=substr($vl_c_z04,0,strlen($vl_c_z04)-2)."UTC";
if (($timestamp = strtotime($vl_c_z04)) === false) {
$vl_c_z09="19610123060000";
} else {
$vl_c_z09=date('YmdHis', $timestamp);
}
} else {
$vl_c_z09="now()";
}
} else {
$vl_c_z09=date('YmdHis', $timestamp);
}

  3. Re: Decode Date?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-17 21:02:18 - In reply to message 1 from Petar
The PHP function strtotime is usually very smart to decode dates in any format.

  4. Re: Decode Date?   Reply   Report abuse  
Picture of Petar Petar - 2007-10-18 06:41:13 - In reply to message 3 from Manuel Lemos
Hi,

Thank you for your responce. I know about strtotime - its very smart but it seems its not smart enought:

if "Date: Thu, 18 Oct 2007 06:28:48 UT" --> echo '<h2>'.$decoded[0]['Headers']['date:'].' --> '.date("Y-m-d H:i:s",strtotime($decoded[0]['Headers']['date:'])).'</h2>'; returns "Thu, 18 Oct 2007 06:28:48 UT --> 1970-01-01 02:00:00"

I know this is a valid date format. I just want to have a SMART function able to decode ANY valid (and not absolutely valid) Date formats. there are many mails in my mailbox with strange date formats.

Please tell if you know about such good php function.

Thank you!