Page 1 of 1

how to display last month in full textual format

Posted: Mon Dec 18, 2006 4:03 pm
by konstandinos
hello folk

i can get last month numerically by simply going date('m')-1 (which would currently return 11)

but i want the format date('F') -> ie: November

obviously date('F')-1 doesn't work.

any ideas?

thanks

Posted: Mon Dec 18, 2006 4:05 pm
by John Cartwright
Why not simply do

Code: Select all

echo 'November';
I don't quite get what your after. :?

Posted: Mon Dec 18, 2006 4:08 pm
by volka

Code: Select all

echo date('F', strtotime('-1 month'));

Posted: Mon Dec 18, 2006 4:09 pm
by konstandinos
it needs to be automated. i dont want to have to hard-code the last month in an echo statement. since in one month's time that will change (pardon me being to patronizing).

so basically i want date('m')-1 functionality, but instead of displaying 11, i want to display november (and when we're in february i want it to say january etc).

make sense?

Posted: Mon Dec 18, 2006 4:10 pm
by John Cartwright
konstandinos wrote:it needs to be automated. i dont want to have to hard-code the last month in an echo statement. since in one month's time that will change (pardon me being to patronizing).

so basically i want date('m')-1 functionality, but instead of displaying 11, i want to display november (and when we're in february i want it to say january etc).

make sense?
My bad, I took what you said in the completely wrong sense.. one of those days you know? Though you meant you wanted the 2nd last month of the year.. for whatever reason.

Posted: Mon Dec 18, 2006 4:11 pm
by konstandinos
works like a charm, thanks volka. thanks for your help too jcart

Posted: Mon Dec 18, 2006 4:36 pm
by konstandinos
ok another problem with date...

im basically pullin up historical dates, which have been stored in my dbase as YYYY-mm-dd, and i'm echo'ing them as Month_name, YYYY.

ie: stored as 2006-12-18, and echo'ed as 'December, 2006'.

so now say that one of my dates is 2006-01-21.

how do i use the date() function to print 'January, 2006'?

Posted: Mon Dec 18, 2006 4:44 pm
by volka
Again strtotime is your friend to get the unix timestamp you can use with date().
see http://de2.php.net/strtotime and http://de2.php.net/date