Jump to content

[SOLVED] Turning 04 into April


jaymc

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.