Member Avatar for angiesavio

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
Member Avatar for angiesavio

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

Member Avatar for LastMitch

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

Member Avatar for diafol

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.

Member Avatar for angiesavio

Closing this topic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.