jaymc Posted April 20, 2007 Share Posted April 20, 2007 How can I turn 04 into April I tried date(F, 04); but it obviously wants the day and year aswell for that to work which in my script wont be available The work around is just have a load of if statements, but thats not very practically Any simplied function or way around it 01 = Jan 02 = Feb etc.. Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/ Share on other sites More sharing options...
per1os Posted April 20, 2007 Share Posted April 20, 2007 Just use an array for the conversion <?php $monthArr = array(01 => "Jan", 02 => "Feb", 03 => "Mar", 04 => "April"); print $monthArr[04]; ?> As far as converting I guess you could do something like this <?php $April = mktime(0,0,0,4,1,2007); $displayDate = date('F', $April); ?> Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234044 Share on other sites More sharing options...
Lumio Posted April 20, 2007 Share Posted April 20, 2007 <?php $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); echo $months[(4-1)]; ?> ... to slow Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234045 Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 i upgraded this to a switch() at home... but i dont have it here :-) it works perfectly well enough :-) <? function switch_month($m){ while($m{0}=="0") $m = substr($m,1); $m = strtolower($m); if($m==1) $M="january"; if($m==2) $M="february"; if($m==3) $M="march"; if($m==4) $M="april"; if($m==5) $M="may"; if($m==6) $M="june"; if($m==7) $M="july"; if($m== $M="august"; if($m==9) $M="september"; if($m==10) $M="october"; if($m==11) $M="november"; if($m==12) $M="december"; if($m==january) $M="1"; if($m==february) $M="2"; if($m==march) $M="3"; if($m==april) $M="4"; if($m==may) $M="5"; if($m==june) $M="6"; if($m==july) $M="7"; if($m==august) $M="8"; if($m==september) $M="9"; if($m==october) $M="10"; if($m==november) $M="11"; if($m==december) $M="12"; return $M; } ?> Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234049 Share on other sites More sharing options...
kenrbnsn Posted April 20, 2007 Share Posted April 20, 2007 The second argument for the date() function needs to be a UNIX timestamp. If you really want to use the date() function, you can do: <?php $mnth = '04'; $ascii_mnth = date('F',strtotime(date('Y') . '-' . $mnth . '-01')); echo $ascii_mnth; ?> Much simpler would be to use an array: <?php $mnths = array('','January','February','March','April','May','June','July','August','September','October','November','December'); $mnth = '04'; $ascii_mnth = $mnths[intval($mnth)]; echo $ascii_mnth; ?> Ken Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234052 Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 there we go... rechanged it :-) <? function switch_month($m){ while($m{0}=="0") $m=substr($m,1); $m=strtolower($m); switch($m){ case "1": return "january"; break; case "2": return "february"; break; case "3": return "march"; break; case "4": return "april"; break; case "5": return "may"; break; case "6": return "june"; break; case "7": return "july"; break; case "8": return "august"; break; case "9": return "september"; break; case "10": return "october"; break; case "11": return "november"; break; case "12": return "december"; break; case "january": return "1"; break; case "february": return "2"; break; case "march": return "3"; break; case "april": return "4"; break; case "may": return "5"; break; case "june": return "6"; break; case "july": return "7"; break; case "august": return "8"; break; case "september": return "9"; break; case "october": return "10"; break; case "november": return "11"; break; case "december": return "12"; break; } } echo switch_month(rand(1,12)); ?> Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234057 Share on other sites More sharing options...
richardw Posted April 20, 2007 Share Posted April 20, 2007 I use a variation of the last posting, -- Rather this does just the Opposite, April into '04' <? $mdigit = "$month"; switch($mdigit) { case "January"; $m1 = "01"; break; case "February"; $m1 = "02"; break; case "March"; $m1 = "03"; break; case "April"; $m1 = "04"; break; case "May"; $m1 = "05"; break; case "June"; $m1 = "06"; break; case "July"; $m1 = "07"; break; case "August"; $m1 = "08"; break; case "September"; $m1 = "09"; break; case "October"; $m1 = "10"; break; case "November"; $m1 = "05"; break; case "December"; $m1 = "06"; break; } echo ""; echo $m1; ?> Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234075 Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 ya... mine goes both ways... 04 --> april --> 04 its helpful for calendars, and all that likeness :-) Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234087 Share on other sites More sharing options...
jaymc Posted April 21, 2007 Author Share Posted April 21, 2007 Cheers!! Resolved Link to comment https://forums.phpfreaks.com/topic/47892-solved-turning-04-into-april/#findComment-234871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.