note 31392 added to function.getdate
| From: | sol2ray at yahoo dot com | Date: | Sun, 20 Apr 2003 07:49:53 +0000 |
| Subject: | note 31392 added to function.getdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46832@lists.php.net to get a copy of this message | ||
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."
--
http://www.php.net/manual/en/function.getdate.php
http://master.php.net/manage/user-notes.php?action=edit+31392
http://master.php.net/manage/user-notes.php?action=delete+31392
http://master.php.net/manage/user-notes.php?action=reject+31392