Hướng dẫn rfc-822 date-time php

I have a date field on my database. the date format as following.

June 17, 2013

Im using the format as

date("F j, Y");

So my question is there a way that i can display this date in RFC-822 format using php? or do i need to start saving the date in RFC-822 format from now on? Thanks in advance.

asked Jun 17, 2013 at 6:50

2

Neither.

From now on you have to start using format supplied by database.
You have to understand the difference between storage format and display formatting. It's different matters. When storing data in mysql, you have to follow mysql rules. So, instead of June 17, 2013 you have to store 2013-06-17.

And then convert at output to whatever format required - not limited to a single one but whatever format is demanded by destination.

answered Jun 17, 2013 at 6:58

Hướng dẫn rfc-822 date-time php

Your Common SenseYour Common Sense

156k39 gold badges208 silver badges331 bronze badges

2

Using the following syntax, you can display current time in RFC822 Format.

$date = new DateTime('2000-01-01');
echo $date->format(DateTime::RFC822);

answered Jun 17, 2013 at 6:53

DevZer0DevZer0

13.3k6 gold badges25 silver badges51 bronze badges

0

None of the other answers worked for me, so this is what worked... to take a date in PHP and output it in RFC822:

date("D, d M Y G:i:s T", strtotime($date));

Hope that helps others.

answered Apr 25, 2017 at 15:16

Hướng dẫn rfc-822 date-time php

Dan GoodspeedDan Goodspeed

3,4324 gold badges24 silver badges35 bronze badges

2

As was pointed out your best bet is to change the way you are storing your dates to something other then a string. date("Y-m-d", strtotime($date)) can assist you in this endeavor.

But to solve the immediate need you can utilize use strtotime, date and the DATE_RFC822 constant to get you what you are looking for.

echo date(DATE_RFC822, strtotime($value));

See First example on php date documentation

answered Jun 17, 2013 at 6:55

OrangepillOrangepill

24.4k3 gold badges40 silver badges63 bronze badges

As @ashleedawg and others mentioned in some comments the simplest solution that works:

date("D, d M Y H:i:s O", strtotime($date));

Mind the "H" and the "O" ;)
Thanks!

answered Nov 24, 2020 at 10:59

romekromek

5551 gold badge5 silver badges13 bronze badges

date_format(date(your database field), '%D, %j %M %t')

and what type of format you want just see the link date and time format for Mysql

answered Jun 17, 2013 at 7:33

You can save it as TimeStamp in database and show it RFC822 format

date(DATE_RFC822, time());

answered Dec 23, 2016 at 18:51

Hướng dẫn rfc-822 date-time php

YuseferiYuseferi

7,15711 gold badges61 silver badges96 bronze badges

1

This is the only solution that worked for me:

date("D, d M Y H:i:s T", strtotime($date));

Other examples above that didn't work include using the DATE_RFC822 format specifier, which puts out a 2-digit year, instead of 4 digits. Then the other suggestion to use G:i:s for time doesn't work because G specifies no leading zeroes, so you'll get 2:00:00 instead of 02:00:00.

answered Jul 6, 2020 at 2:01

Hướng dẫn rfc-822 date-time php

don't use T at the end but an "O", it works for me

answered Aug 11, 2021 at 14:45

Hướng dẫn rfc-822 date-time php

1

If you want to date format something in PHP for RFC-822 , then just do this...

date('r', strtotime($date))

'r' » RFC 2822 formatted date Example: Thu, 21 Dec 2000 16:01:07 +0200

Source: PHP.net: DateFormat

But, as other stated, you don't want to store this in your database! However, you'll need to use r for other things, like XML-RSS date time formats...

All date-times in RSS conform to the Date and Time Specification of RFC 822... (Source: RSS 2.0 Specification.)

answered Dec 19, 2021 at 2:07

HoldOffHungerHoldOffHunger

16.7k8 gold badges92 silver badges121 bronze badges

1