Page 1 of 1
Month convert function?
Posted: Fri Dec 02, 2005 1:03 pm
by spacebiscuit
Hi,
Does anyone know if there is a function that given a month number (1-12) it will return the month name.
I could write my own case/select or function but wanted to know if there was an in-built function.
By the way foobar, I used the regex again today on another application, working well!
Thnaks,
Rob.
Re: Month convert function?
Posted: Fri Dec 02, 2005 1:16 pm
by foobar
robburne wrote:
Does anyone know if there is a function that given a month number (1-12) it will return the month name.
I could write my own case/select or function but wanted to know if there was an in-built function.
Try this:
Code: Select all
$month = 5; //Let's say the months is May
echo date('m', mktime(0, 0, 0, $month, 0, 0));
robburne wrote:By the way foobar, I used the regex again today on another application, working well!
Glad to hear!

Posted: Fri Dec 02, 2005 1:16 pm
by Charles256
http://us3.php.net/date
read the entire page very very carefully. not being sarcastic,it can be tricky to find your answer.though i promise it's there.
Posted: Fri Dec 02, 2005 2:09 pm
by wtf
Just had this problem yesterday. With strtotime you have to pass any value for a valid year in order for it to return the month. Anyone knows why?
This will also work
Code: Select all
$month = 5; //Let's say the months is May
echo date('m', strtotime("$month 1970");
Posted: Fri Dec 02, 2005 2:24 pm
by foobar
See? PHP is great. There are so many ways to do the same thing!

Posted: Fri Dec 02, 2005 3:57 pm
by spacebiscuit
Code: Select all
<?
$month = 5;
echo date('m', strtotime("$month 1970");
?>
Parse error: syntax error, unexpected ';' in d:\Software\Apache\htdocs\skytrax\test.php on line 4
I tried replacing the quotations with an apostrophe but still getting an error.
Rob.
Posted: Fri Dec 02, 2005 3:58 pm
by Charles256
coiunt how many left ( and how many right ) you have...if the two numbers are not equal you screwed up somewhere

Posted: Fri Dec 02, 2005 4:07 pm
by spacebiscuit
Duh!
Thx

Posted: Fri Dec 02, 2005 4:08 pm
by wtf
awww....
Code: Select all
$month = 5; //Let's say the months is May
echo date( 'm', strtotime("$month 1970") );
[/quote]
Posted: Fri Dec 02, 2005 4:09 pm
by spacebiscuit
Ok added the closing bracket and changed the year to 2005 but
Code: Select all
Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in
Rob.
Posted: Fri Dec 02, 2005 4:16 pm
by John Cartwright
try:
Code: Select all
$month = 5; //Let's say the months is May
echo date('M', strtotime("$month/01"));
Posted: Fri Dec 02, 2005 6:28 pm
by Jenk
Seems stupid to have nested functions run
just to receive the name of a month..
Code: Select all
<?
$months = array('Jan', 'Feb', 'Mar', 'etc.');
$month = $months[--$num];
?>
Posted: Mon Dec 05, 2005 7:47 am
by spacebiscuit
Hi,
I found that this worked beter.....
$x=date('M',mktime(0,0,0,date(n),date(j),date(y)));
Thanks,
Rob.