note 48299 added to function.date
| From: | chirpyATchirpysDOTcom at osu1 dot php dot net | Date: | Sat, 18 Dec 2004 11:03:45 +0000 |
| Subject: | note 48299 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81969@lists.php.net to get a copy of this message | ||
A quick function I just knocked up to create the English ordinal suffix of a day that is passed to
do it. I'm sure there must be one somewhere, but I can't find it :)
<?php
function suffix ($day) {
$suffices = array("th", "st", "nd", "rd", "th",
"th", "th", "th", "th", "th");
$original_formatting = $day;
if (strlen($day) == "1") { $day = "0" . $day; }
$ending = $day{1};
if ($day{0} != "1") {
$thesuffix = $suffices[$ending];
} else {
$thesuffix = "th";
}
$formatted_day = $original_formatting . $thesuffix;
return $formatted_day;
}
?>
For example:
<?php
suffix(2); // Returns 2nd
suffix(02); // Returns 02nd
suffix(17); // Returns 17th
?>
It's probably not the most efficient way possible, but it works. Hope it helps somebody :)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48299
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48299&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48299&report=yes
Search -- http://master.php.net/manage/user-notes.php