How to convert the Drupal node “created” date to something readable

By David Pratt / Tags: , / 4 Comments / Published: 08-08-09

Should you want to display a user readable version of a Drupal 6 date field, the following code snippet might be of use to you:

<?php echo date("D, j M Y \a\\t G:i", $created_date) ?>

For example, if created_date were to equal “1249641973”, it would get rendered as “Fri, 7 Aug 2009 at 11:46″. Nice.

Category: Tech

Tags: ,

Posted: on August 8th, 2009 at 7:57 pm.

Feeds: RSS 2.0

4 Responses to “How to convert the Drupal node “created” date to something readable”

Bob Thomas June 25th, 2010 at 12:23 am

That snippet is neat –
now say that I would like to import the node-created-date field into a spreadsheet – either openoffice suite or MS excel – could you please tell me what sort of formula would to that, “Open sesame!” type of trick?

McSleazy February 11th, 2011 at 10:15 am

Thanks.

You could take a step further and put this in your template.php:

<?php
function readabledate($enterdate) {
$newdate = date("D, j M Y", $enterdate);
return $newdate;
}
?>

Then, whenever you want a readable date, just use ‘readable date’ – such as:

<?php
readabledate($created);
?>

But you probably already knew that. ;)

Glenn May 13th, 2011 at 12:21 pm

hi there, new to drupal and this was really helpful thank you :-)

name March 8th, 2012 at 5:05 pm

Please do not use the “date” function, use the format_date(), is a drupal function :
http://api.drupal.org/api/drupal/includes!common.inc/function/format_date/7

look the api

Leave a reply