note 74153 added to function.date

From: Date: Tue, 27 Mar 2007 21:28:12 +0000
Subject: note 74153 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-124858@lists.php.net to get a copy of this message
Here is a basic function that, depedent upon the date, will display Today at TIME, Yesterday at TIME, or Month Day, Year. <?php function dateFormat($tdate){ $today = "<strong>Today</strong>"; $yesterday = "Yesterday"; $date_format = '%M %D, %Y'; $gdatequery = "SELECT DATE_FORMAT('".$tdate."', '".$date_format."') AS newdate FROM DUAL;"; $gdate = mysql_query($gdatequery); $gdate = mysql_fetch_assoc($gdate); $gdatex = &$gdate["newdate"]; if(($gdatex)==(date("F dS, Y"))): $today_date_check = date("g:i:s A",strtotime($tdate)); $g = $today . " at ". $today_date_check; elseif(($gdatex)==(date("F dS, Y",strtotime(&$yesterday)))): $yesterday_date_check = date("g:i:s A",strtotime($tdate)); $g = $yesterday . " at " . $yesterday_date_check; else: $g = $gdatex; endif; return $g; } ?> You'd just use something like: <?=dateFormat($lastpost["date"];?> .. replacing the parameter with the appropriate value. Paul ---- Server IP: 64.71.164.2 Probable Submitter: 70.167.85.213 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/74153 Del: integrated -- https://master.php.net/note/delete/74153/integrated Del: useless -- https://master.php.net/note/delete/74153/useless Del: bad code -- https://master.php.net/note/delete/74153/bad+code Del: spam -- https://master.php.net/note/delete/74153/spam Del: non-english -- https://master.php.net/note/delete/74153/non-english Del: in docs -- https://master.php.net/note/delete/74153/in+docs Del: other reasons-- https://master.php.net/note/delete/74153 Reject -- https://master.php.net/note/reject/74153 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124858) next »