Created
December 7, 2010 00:37
-
-
Save niczak/731272 to your computer and use it in GitHub Desktop.
Functions to add ordinal suffix to day values and convert integer months to string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add ordinal suffix to day | |
function fnDay_Format($iday) | |
{ | |
if(empty($iday)) | |
die("No parameter passed to function."); | |
else | |
$iday = intval($iday); | |
if($iday < 1 || $iday > 31) | |
die("Invalid parameter passed to function."); | |
$asuffix = array('th','st','nd','rd','th','th','th','th','th','th'); | |
if (($iday %100) >= 11 && ($iday % 100) <= 13) | |
$sdate = $iday. 'th'; | |
else | |
$sdate = $iday.$asuffix[$iday % 10]; | |
return $sdate; | |
} | |
// Convert integer month to string | |
function fnMonth_Format($imonth) | |
{ | |
if(empty($imonth)) | |
die("No parameter passed to function."); | |
else | |
$imonth = intval($imonth); | |
if($imonth < 1 || $imonth > 12) | |
die("Invalid parameter passed to function."); | |
$amonths = array(1=>"January", 2=>"February", 3=>"March", | |
4=>"April", 5=>"May", 6=>"June", 7=>"July", 8=>"August", | |
9=>"September", 10=>"October", 11=>"November", 12=>"December"); | |
return $amonths[$imonth]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment