note 20269 modified in function.getdate by irchtml

From: Date: Wed, 25 Feb 2004 14:22:59 +0000
Subject: note 20269 modified in function.getdate by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65723@lists.php.net to get a copy of this message
[Editor's note: To avoid re-inventing the wheel, use: $dat = date('l \t\h\e Js \o\f F Y'); ] Heres a little bit of code to create a posh date : <?php $today = getdate(); $mon = $today['month']; $day = $today['weekday']; $dayn = $today['mday']; $year = $today['year']; if ($dayn == 1) { $ex = "st"; } elseif ($dayn == 2) { $ex = "nd"; } elseif ($dayn == 3) { $ex = "rd"; } elseif ($dayn == 21) { $ex = "st"; } elseif ($dayn == 22) { $ex = "nd"; } elseif ($dayn == 23) { $ex = "rd"; } elseif ($dayn == 31) { $ex = "st"; } elseif ($dayn == 32) { $ex = "nd"; } else { $ex = "th"; } $dat = sprintf("%s the %s%s of %s %s",$day,$dayn,$ex,$mon,$year); ?> $dat would be something like this: Thursday the 28th of March 2002 --was-- [Editor's note: To avoid re-inventing the wheel, use: $dat = date("l \t\h\e Js \o\f F Y"); ] Heres a little bit of code to create a posh date : <?php $today = getdate(); $mon = $today['month']; $day = $today['weekday']; $dayn = $today['mday']; $year = $today['year']; if ($dayn == 1) { $ex = "st"; } elseif ($dayn == 2) { $ex = "nd"; } elseif ($dayn == 3) { $ex = "rd"; } elseif ($dayn == 21) { $ex = "st"; } elseif ($dayn == 22) { $ex = "nd"; } elseif ($dayn == 23) { $ex = "rd"; } elseif ($dayn == 31) { $ex = "st"; } elseif ($dayn == 32) { $ex = "nd"; } else { $ex = "th"; } $dat = sprintf("%s the %s%s of %s %s",$day,$dayn,$ex,$mon,$year); ?> $dat would be something like this: Thursday the 28th of March 2002 http://www.php.net/manual/en/function.getdate.php

« previous php.notes (#65723) next »