How to Convert a MySQL Timestamp to an RFC-822 PHP

104 14
    • 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

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.

"Society & Culture & Entertainment" MOST POPULAR

Ways to Use Sea Glass

How to Biscuit Joints

Making a Kite: Tie Support Sticks

How to Increase Specific Gravity

A Typical Plant's Cell Structure

How the Eye Perceives Color

Major Effects of Global Warming