0

Good day,

I have the following date that I get from my imap_fetch_overview PHP function :

$overview = imap_fetch_overview($inbox, $email_number, 0);

...

$date_event = $overview[0]->date;

This outputs a date like 'Fri, 30 Jun 2017 16:27:44 +0000 (UTC)'

In the meantime I have set my default timezone as following :

date_default_timezone_set('Europe/Brussels');

What I would like now is to be able to retrieve my $date_event in a format dd.mm.yyyy HH:mm:ss (local time, in my case 30.06.2017 18:27:44).

I have therefore tried :

$date_event_formated = $date_event('dd.mm.YYYY HH:ii:ss');

When calling 'echo $date_event_formated;', the only thing I get is a Fatal error.

So sorry if the question might sound silly, but I don't really understand what I am doing wrong here? Before bothering you, I looked at the reference website http://php.net/manual/fr/function.date.php but I may have missed something.

Thanks very much for your time and appreciated help.

1

3 Answers 3

2

While there is nothing wrong with Jakub's answer, using php 5.3 and up you can also use DateTime::createFromFormat, using an exact mask to parse the incoming date-string.

$oldDate = 'Fri, 30 Jun 2017 16:27:44 +0000 (UTC)';
$date = DateTime::createFromFormat('D, d M Y H:i:s T e', $oldDate);
echo $date->format('Y-m-d');
Sign up to request clarification or add additional context in comments.

Comments

1

strtotime() is able to handle the format that you have and convert it into timestamp. Then you can use it to format date in whatever format you want with date() function:

$date_event = 'Fri, 30 Jun 2017 16:27:44 +0000 (UTC)';
echo date('d.m.Y H:i:s',strtotime($date_event));
//outputs: 30.06.2017 18:27:44

Here's working example:

https://3v4l.org/obfNB

Comments

1
use strtotime:

$date_event = 'Fri, 30 Jun 2017 16:27:44 +0000 (UTC)';
echo date('d.m.Y H:i:s',strtotime($date_event));

1 Comment

Thanks a lot Vishal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.