note 112253 deleted from function.date by peehaa

From: Date: Fri, 06 Jan 2017 15:56:17 +0000
Subject: note 112253 deleted from function.date by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208709@lists.php.net to get a copy of this message
Note Submitter: scott at keenot dot es ---- If anyone needs a really fast function for converting a datetime string (i.e. as retrieved from a MySQL DATETIME entry) into a human-friendly time output analogous to date($format, $time), here's a useful function. <?php function fdate($datetimestring = '1970-01-01 00:00:00', $format = 'U') { // Create a datetime object, return it formatted // If you want to give credit for this somewhere, thanks. // You really don't have to though; this is kinda obvious $dt = new DateTime($datetimestring); return $dt->format($format); } ?> The main purpose of this is to reduce lines of code and allow inline coding. For example: <?php /* ... */ echo "This page was submitted on ".fdate($row['created'], 'F j, Y g:i:s A')." and last modified ".fdate($row['modified'], 'F j, Y g:i:s A')."<br />\n"; /* ... */ ?>

« previous php.notes (#208709) next »