On Thu, 16 Nov 2006, Tris wrote:

> I've got a date function using: Y-m  eg: 2006-11 (for today)
>
> I want to get last month (2006-10) etc, and when I hit JAn, loop to 2005-12 ..
>
> Is this easy?

There will be cleaner/more efficient ways to do it (Google for PHP date
manipulation) but the operation is pretty damn simple:

function get_last_month() {
    return (date('m') == 1)?
        join('/', array(date('Y')-1, '12')) :
        join('/', array(date('Y'), date('m')-1)) ;
}

That ought to do it - if the month is 1 (Jan), then take one off the year
and use 12 for the month, otherwise just drop one off the month.

Simple eh?  ;)

Cheers

Dave P



____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
       Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to