By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,616 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,616 IT Pros & Developers. It's quick & easy.

beginner problem - using date("M", $i) where $i is an integer

P: n/a
Hi,

I am trying to use the following function:
echo date("M", $i)
to echo the date that the value of a variable, $i, represents (eg. 1 =
Jan, 5 = May, 11 = Nov). Unfortunetely, it returns only Jan for any
number which I assume is the 1970 date that this function returns when
you screw up. I know that when I have the string value of '2005-05-01'
in a variable, I have to convert it in the following function:
echo date("M", strtotime($strdate))
Is something similar required when I use an integer? Thanks

Burnsy

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


bi******@yahoo.co.uk wrote:
Hi,

I am trying to use the following function:
echo date("M", $i)
to echo the date that the value of a variable, $i, represents (eg. 1 =
Jan, 5 = May, 11 = Nov). Unfortunetely, it returns only Jan for any
number which I assume is the 1970 date that this function returns when
you screw up. I know that when I have the string value of '2005-05-01'
in a variable, I have to convert it in the following function:


The second parameter to the date() function is the number of seconds
since 1970-01-01 (the UNIX beginning of time). To do what you want to
do, use

echo date("M",strtotime('2005-'.$i.'-01'));

Ken

Jul 17 '05 #2

P: n/a
This is slightly more efficient, I think:

echo date("M", mktime(0, 0, 0, $i));

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.