Results 1 to 6 of 6

Thread: php and mysql date stuff

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: php and mysql date stuff

    Use queries with MySQL's Date and Time Functions...

    SELECT * FROM myTable WHERE MONTH(myTimeStamp) > MONTH(CURDATE())-6 AND YEAR(myTimeStamp) = YEAR(CURDATE())

    This query will get all rows where myTimeStamp is the same year, and within 6 past months of the current date. To get a count of these rows, rather than the rows themselves, change the query to:

    SELECT COUNT(*) AS 'referringName' FROM myTable WHERE MONTH(myTimeStamp) > MONTH(CURDATE())-6 AND YEAR(myTimeStamp) = YEAR(CURDATE())

    The "AS 'referringName'" part is so that when you get your result in PHP, you can use mysql_fetch_assoc and call it by $sql_row['referringName'].

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    Re: php and mysql date stuff

    awesome

    now say i just want to get the count of anything of the month from 5 months ago.

    would i do something like this?
    SELECT * FROM myTable WHERE (MONTH(myTimeStamp) > MONTH(CURDATE())-6 and MONTH(myTimeStamp) < MONTH(CURDATE())-5) AND YEAR(myTimeStamp) = YEAR(CURDATE())

Posting Permissions

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



Click Here to Expand Forum to Full Width