note 68106 added to function.strftime
| From: | brianmcallister at osu1 dot php dot net | Date: | Thu, 13 Jul 2006 13:42:01 +0000 |
| Subject: | note 68106 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114732@lists.php.net to get a copy of this message | ||
In response to the function supplied by "fackelkind honorsociety de" for calculating the
day suffix.
While your code is short and sweet, it doesn't actually produce the correct results. Passing 13
to the function should return "th" and not "rd". The following functions should
work...
<?php
// For those of you who don't detest the Switch statement
function getDaySuffix($dayOfTheMonth) {
switch ($dayOfTheMonth) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
case 21: return "st";
case 22: return "nd";
case 23: return "rd";
case 31: return "st";
default: return "th";
}
}
// Another version for those of you who detest the Switch statement
function getDaySuffix($dayOfTheMonth) {
$suffix = array(
1 => "st",
2 => "nd",
3 => "rd",
21 => "st",
22 => "nd",
23 => "rd",
31 => "st");
return isset($suffix[$dayOfTheMonth]) ? $suffix[$dayOfTheMonth] : "th";
}
?>
----
Server IP: 194.246.101.61
Probable Submitter: 82.232.9.222
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strftime.php
Edit -- http://master.php.net/note/edit/68106
Del: integrated -- http://master.php.net/note/delete/68106/integrated
Del: useless -- http://master.php.net/note/delete/68106/useless
Del: bad code -- http://master.php.net/note/delete/68106/bad+code
Del: spam -- http://master.php.net/note/delete/68106/spam
Del: non-english -- http://master.php.net/note/delete/68106/non-english
Del: in docs -- http://master.php.net/note/delete/68106/in+docs
Del: other reasons-- http://master.php.net/note/delete/68106
Reject -- http://master.php.net/note/reject/68106
Search -- http://master.php.net/manage/user-notes.php