0

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
5
Contributors
7
Replies
25
Views
3 Years
Discussion Span
Last Post by diafol
0

I mean if my variable have value 5
then output should be May not January

0

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; 
?>
0

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);

Edited by Coyx

0

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...

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.