|
-
Aug 8th, 2009, 01:57 PM
#1
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'].
-
Aug 8th, 2009, 03:08 PM
#2
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|