Month convert function?
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Month convert function?
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.
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?
Try this: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.
Code: Select all
$month = 5; //Let's say the months is May
echo date('m', mktime(0, 0, 0, $month, 0, 0));Glad to hear!robburne wrote:By the way foobar, I used the regex again today on another application, working well!
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
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.
read the entire page very very carefully. not being sarcastic,it can be tricky to find your answer.though i promise it's there.
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
This will also work
Code: Select all
$month = 5; //Let's say the months is May
echo date('m', strtotime("$month 1970");-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Code: Select all
<?
$month = 5;
echo date('m', strtotime("$month 1970");
?>I tried replacing the quotations with an apostrophe but still getting an error.
Rob.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
awww....
[/quote]
Code: Select all
$month = 5; //Let's say the months is May
echo date( 'm', strtotime("$month 1970") );-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Ok added the closing bracket and changed the year to 2005 but
Rob.
Code: Select all
Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
try:
Code: Select all
$month = 5; //Let's say the months is May
echo date('M', strtotime("$month/01"));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];
?>-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm