how to display last month in full textual format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

how to display last month in full textual format

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why not simply do

Code: Select all

echo 'November';
I don't quite get what your after. :?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

echo date('F', strtotime('-1 month'));
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Last edited by John Cartwright on Mon Dec 18, 2006 4:16 pm, edited 1 time in total.
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

Post by konstandinos »

works like a charm, thanks volka. thanks for your help too jcart
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

Post 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'?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply