Jump to content

Date & Time Formating


stephenl7

Recommended Posts

Hello

 

I am trying to store the date and time from a email header (retrived using imap_fetch_overview) in a MYSql database

 

My current code seems logical, however doesn't work

 

    // read datetime from header

    $datestr = $overview->date;

    // format
    $dateTime = DateTime::createFromFormat('D, d M Y H:i:s O', $datestr);

    $errors = DateTime::getLastErrors();
    if (!empty($errors['warnings'])) {
    echo "Invalid Date\n"; }

 

    // convert to mysql format   
    $date = $dateTime->format('Y-m-d H:m:s');

 

Reported error

Fatal error: Call to a member function format() on a non-object in

 

Any advise and suggestions would be appreciated

 

Thank you

 

Link to comment
Share on other sites

Your object creation is failing, returning a boolean false.  Make sure your date string matches your format string.

 

Right now you are telling it to create the string from a date that looks like "Mon, 01 Jan 2013 23:40:12 +0500".

 

I would suggest dumping the $datestr variable, and making sure it matches that format.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.