RFC date()

by Andy Prevost

Thursday December 28 2023

PHP documentation shows that 

date("r"), and note that this is equivalent to date("d-M-Y H:i:s O")

will provide an RFC 2822 / RFC 5322 formatted date (as in: Thu, 21 Dec 2000 16:01:07 +0200) ... 

That is correct. However, keep in mind that may work when creating the header for an email. I have found occasions when that doesn't work and generates an "incorrect format" error. The correct way of using date in an email header is to format to RFC 2060 format (read the specification, view the examples). To avoid errors, we must use the latter RFC format that includes the time zone (as in: Thu, 21 Dec 2000 19:01:07 +0500 (EST) ), meaning include the Time Zone abbreviation.

There are two ways to get the correct date format:

date("d-M-Y H:i:s O (T)")

or

date("r (T)")

Your choice, I prefer the first.

 

◀ Previous Next ▶

Post a Comment