note 68106 deleted from function.strftime by derick

From: Date: Sat, 04 Nov 2006 10:40:03 +0000
Subject: note 68106 deleted from function.strftime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119373@lists.php.net to get a copy of this message
Note Submitter: brian mcallister ---- 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"; } ?>

« previous php.notes (#119373) next »