note 55478 deleted from function.date by derick

From: Date: Sun, 15 Jan 2006 12:44:03 +0000
Subject: note 55478 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101834@lists.php.net to get a copy of this message
Note Submitter: thammer at rtccom dot com ---- Relative dates (ie, Today, Yesterday, etc..) are missing from the date function. So I wrote this function to replace date(). It returns Today, Yesterday, or Day of the Week relative to {today} up to 6 days. Anything older than that, and it will use the formatting you would normally apply to date(). I hope somebody finds this useful. <? //Returns Today,Yesterday, Day of week ('l') //up to 6 days ago. Otherwise it uses $format function RelativeDate($format,$epoch) { $day = date('j',$epoch); $today = date('j',time()); $yday = date('j',strtotime("-1 day")); //account for last month's day switch($day) { case $today: return "Today"; break; case $yday: return "Yesterday"; break; default: //Look up to one week ago for($i=1;$i<=6;$i++) { $pastday = date('j',strtotime("-$i days")); if($day == $pastday) { return(date('l',$epoch)); } } //If we made it to here, just print the format given return date($format,$epoch); } } ?>

« previous php.notes (#101834) next »