note 45517 added to function.date

From: Date: Thu, 09 Sep 2004 14:58:16 +0000
Subject: note 45517 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-76329@lists.php.net to get a copy of this message
The 'S' doesn't work the way you might expect to... for example, on the 251st day of the year date("zS") returns "251th" instead of "251st" Here is an nTh() function I use to achieve the desired effect. function nTh( $n ) { if( $n>4 && $n<21 ) $rtn = "th"; else { $it = substr($n,strlen($n)-1,1); switch( $it ) { default: $rtn = "th"; break; case 1: $rtn = "st"; break; case 2: $rtn = "nd"; break; case 3: $rtn = "rd"; break; } } return $rtn; } ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45517 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45517&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45517&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76329) next »