Top

mySQL Timestamp convert to RSS PubDate


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  5.0 (of 3 scores)
Date Added  Aug 29, 2004
Last Updated  Jan 17, 2006
Tags  convert  mktime  mysql  pubdate  rss  timestamp 

Introduction

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

Grab the Code

<?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

  (2)  RSS
thelem
Comments: 1
 
PHP Snippet:  mySQL Timestamp convert to RSS PubDate
Posted on Jan 19, 2005 10:40 am
Even easier, you can extract a unix timestamp from the database. In the column list of the mysql query, put UNIX_TIMESTAMP(column name)
NBM
Comments: 1
 
PHP Snippet:  mySQL Timestamp convert to RSS PubDate
Posted on Aug 23, 2009 7:01 pm
Or easier yet:

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

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom