How to Convert a MySQL Timestamp to an RFC-822 PHP
- 1). Open a text editor or Web design application and create a new PHP page.
- 2). Add the following code to the page, between the HTML "<body>" "</body>" tags:
<?php
$mysql_timestamp = '2011-09-08 14:30:01';
$rfc_date = date('r', strtotime($mysql_timestamp));
echo "MySQL Timestamp: " . $mysql_timestamp . "<br>";
echo "RFC 2822 Date: " . $rfc_date;
?>
This code creates a variable containing an example date in the MySQL timestamp format. - 3). Use the "date" command to perform the conversion, passing the token "r" to indicate that the output should be in RFC-2822 format. The "strtotime" command converts the MySQL timestamp into the UNIX timestamp expected by the "date" command. Save the page as "date.php."
- 4). Upload the page to your server, then open the page in your Web browser to see the following output:
MySQL Timestamp: 2011-09-08 14:30:01
RFC 2822 Date: Thu, 08 Sep 2011 14:30:01 +0100