mySQL Timestamp convert to RSS PubDate

By Hawkee on Aug 29, 2004

This is very handy for making a yyyymmddhhmmss date look pretty.

<?php
    $year = substr($timestamp, 0, 4);
    $month = substr($timestamp, 4, 2);
    $day = substr($timestamp, 6, 2);
    $hour = substr($timestamp, 8, 2);
    $min = substr($timestamp, 10, 2);
    $sec = substr($timestamp, 12, 2);
    $pubdate = date('D, d M Y H:i:s O', mktime($hour, $min, $sec, $month, $day, $year));
?>

Comments

Sign in to comment.
delta   -  Nov 25, 2010

Why don't use it that way? Please dont forget that the date can be saved in many options, striping that stuff will probably never work...

<?php
$q=mysql_query("select unix_timestamp(column) as ts FROM table;");
$pubdate = date('D, d M Y H:i:s O', @mysql_result($q,0,0));
?>

 Respond  
NBM   -  Aug 23, 2009

Or easier yet:

<?php $pubdate = date('D, d M Y H:i:s O', strtotime($timestamp)); ?>

 Respond  
thelem   -  Jan 19, 2005

Even easier, you can extract a unix timestamp from the database. In the column list of the mysql query, put UNIX_TIMESTAMP(column name)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.