Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jdmonthname function 3

Status
Not open for further replies.

jisoo23

Programmer
Jan 27, 2004
192
US
Ok so I might be going a little nuts here...

I'm using jdmonthname($var,0) to pick up the abbreviated month names like "Jan", "Feb", etc. Here's the problem:

I feed it the number 11 for the first argument and I end up getting "Dec"(?!). It's very strange...I replaced that variable with a 2 and ended up getting "Nov". Has anyone run into this issue before? My web host company is running PHP 4.4.1 and has calendar support enabled...

Thanks,
Jisoo23
 
It could be a bug. Since Julian dates are the number of days and fractions of days since noon GMT on January 1, 4713 BC, both values of "11" and "2" should have produced "Jan".

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Another situation where my understanding of PHP is unable to rely on prior experience from javascript, java, asp or jsp :) I've not done *any* date stuff in php... looks like I may have found a reason to start a new project!

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
That's strange because when I tossed in a "0" and echoed, it didn't print out anything in the html. Looks like I'm going to have to use a case statement for this. How annoying =P
 
I just realized why I'm getting this problem, first argument is a julian DAY, not month. I could just drive my head through my desk right now =/ lol. Does anyone know if there's a proper function that will take a month number and give me the corresponding month name?
 
Something like this should work:
Code:
echo monthName(1);

function monthName($month){
  return date("M", mktime(0, 0, 0, $month, 1, 2000));
}
 
Can't you use a simple array:

Code:
$nameofonth[1]="Jan";
$nameofonth[2]="Feb";
$nameofonth[3]="Mar";
$nameofonth[4]="Apr";
$nameofonth[5]="May";
$nameofonth[6]="Jun";
$nameofonth[7]="Jul";
$nameofonth[8]="Aug";
$nameofonth[9]="Sep";
$nameofonth[10]="Oct";
$nameofonth[11]="Nov";
$nameofonth[12]="Dec";


When you need a name of month just do:
Code:
echo $nameofmonth['somenumber'];

You can even create a small function that checks if the number provided is larger than 12 or less than 1. so as to not have any Errors.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
DRJ478's suggestion would probably work well. Yeah I could use an array, just thought there'd be a function something as useful as this though. I was thinking along the lines of DR's function anyway...thanks everyone for their suggestions!
 
Could you use your original function but pass to it the month number * 29 as the first argument? That should land somewhere in the month that you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top