note 31392 deleted from function.getdate by tomsommer

From: Date: Wed, 15 Sep 2004 16:37:13 +0000
Subject: note 31392 deleted from function.getdate by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76751@lists.php.net to get a copy of this message
Note Submitter: sol2ray at yahoo dot com ---- This is a reply to a posting by :petercawley at hotmail dot com I'm new to php and programming all together ( 6 month learning on my own) but I can think of something better to get the same result. Try the following function instead. function date_sign($mday) { if($mday == 1 || $mday == 21 || $mday == 31) $day_sign = 'st'; elseif ($mday == 2 || $mday == 22 ) $day_sign = 'nd'; elseif($mday == 3 || $mday == 23 ) $day_sign = 'rd'; else $day_sign = 'th'; return $day_sign; } Just use it this way: $date = getdate(); $sign = date_sign($date['mday']); echo $date['weekday'].' '.$date['month'].' '.$date['mday'].$sign.' '.$date['year']; Output: Sunday April 20th 2003 I don't know why you've included 32 in your code, but I've never seen a month with 32 days. Correct me if I'm wrong. Remember "There is more than one way to do it."

« previous php.notes (#76751) next »