note 74153 deleted from function.date by bjori

From: Date: Fri, 20 Apr 2007 09:19:51 +0000
Subject: note 74153 deleted from function.date by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125604@lists.php.net to get a copy of this message
Note Submitter: chaobreederxl at gmail dot com ---- 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

« previous php.notes (#125604) next »