Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191

    Unanswered: date comparison issues...

    Hi all...

    I'm a relative newcomer to php, so pardon me if this is too easy. I've searched various forums and cannot come up with a decent way to do what I want to do.

    I want to do a MySQL query that returns all records that have a signup date between the 1st and last days of last month....

    With the limited date functions in php, I cannot find an easy way to do this without calling a function in the SQL statement. Is there a month() function I'm missing somewhere?

    Any and all feedback is appreciated....
    Tim

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    I want to do a MySQL query that returns all records that have a signup date between the 1st and last days of last month....
    There are a couple of ways, the simplest (if you literally want 'last month') is a WHERE clause in a query like this -

    Code:
    SELECT * FROM your_table WHERE MONTH(your_signup_date_field) = MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH))
    MONTH(your_signup_date_field) returns the month part of your saved dates. The rest gets the month portion of the (current date - one month).

  3. #3
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    That's EXACTLY what I needed. Thanks VERY much for the response.
    Tim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •