Hi all,
I want to print month number in text.
i tried
date("F",$month);
date("F",(int)$month);
date("F",strtotime($month));
but all function return me january
plz help me out
Hi all,
I want to print month number in text.
i tried
date("F",$month);
date("F",(int)$month);
date("F",strtotime($month));
but all function return me january
plz help me out
http://docs.php.net/manual/en/function.date.php
Isn't that what you wanted??
I want to print month number in text.
but all function return me january
Or do you mean January = One??
I mean if my variable have value 5
then output should be May not January
I mean if my variable have value 5 then output should be May not January
@angiesavio
Try this:
<?php
$monthNumber = 5;
$monthName = date("F", mktime(0, 0, 0, $monthNumber, 10));
echo $monthName;
?>
That all seems like a very long way of doing it. Just take your Epoch timestamp and assign it certain values, such as date("m", $myTime); to return number with leading zero, eg; 09 (September).
<?php
$myTime = 1380111299;
echo "The time right now is ".date("H:i d/m/Y", $myTime).".";
//outputs "The time right now is 12:14 25/09/2013."
?>
F will output the month in full text, eg; September. So you could just do... date("F", $myTime);
Why take a variable that has already undergone conversion and convert it back to a different format? Why would you not take just the root variable that generated the number month and convert that one to the full text representation of the month?
If you have to keep ducking and diving over already converted variables like this, you're coding wrong. That's like me taking my code...
<?php
$myTime = 1380111299;
$monthNum = date("m", $myTime);
echo "The month right now is ".$monthNum.".";
//outputs "The month right now is 09."
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
echo $monthName; //output: September
?>
Instead of just doing...
<?php
$myTime = 1380111299;
$monthNum = date("m", $myTime);
echo "The month right now is ".$monthNum.".";
//outputs "The month right now is 09."
$monthName = date("F", $myTime);
echo $monthName; //output: September
?>
Just strikes me as... odd...
If this is the only way you're going to use it (no localisation), why not...
$mStrings = array(1=>"January","February","March"...);
$index = (int) $month;
if($index > 0 && $index < 13)
{
$output = $mStrings[$index];
}
LM's way is pretty easy too.
Closing this topic
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.