Search code examples
phpmysqltimestampimap

php's imap_fetch_overview() date field format as MySQL timestamp


php's imap_fetch_overview() date key is a date format like this:

Thu, 22 Aug 2013 07:53:32 -0400

Yikes. Is it possible to customize the format of the date? I am not seeing anything in the docs so I assume not. What I need to do is convert this to MySQL's timestamp format.


Solution

  • You can't customize an included PHP function/library without rewriting and recompiling source. A class could be customized, or inherited and adjusted. But in this case, what you can do is a simple strtotime() of the date/time. Then convert it to MySQL datetime.

    $array=imap_fetch_overview();
    $unixTimestamp=strtotime($array['date']);
    echo date("Y-m-d H:i:s", $unixTimestamp);