Forum Moderators: coopster
Any help would be appreciated.
Thanks!
SELECT DAYOFWEEK(myDateField), DAYOFWEEK(NOW()) FROM mytable
WHERE DAYOFWEEK(myDateField) = DAYOFWEEK(NOW());
[dev.mysql.com...]
How would you further modify to restrict by time of day? For example, suppose you ran this query at noon. The query would show all revenue for today (Tuesday) compared to previous Tuesdays. However, it is comparing today's mid-day revenue to the previous Tuesday's full day. How can I restrict it so the time periods are the same, i.e. Tuesday through noon compared to previous Tuesdays through noon?
Thanks in advance for your help!
Rod
Alternatively, If you don't wish to round down to the nearest hour then use:
SELECT DAYOFWEEK(myDateField), DAYOFWEEK(NOW()) FROM `mytable`
WHERE ( DAYOFWEEK(myDateField) = DAYOFWEEK(NOW()) )
AND (myDateField < NOW() );
How can I modify so that results are limited to the actual time and not rounded down?
Here's the actual query if that would help:
SELECT DATE_FORMAT(b.statusdate,'%Y-%m-%d, %a'), count(*), sum(payment)
FROM investreq a, reqstatus b
WHERE a.refnum = b.refnum AND b.status = 'ab'
AND a.curstatus NOT IN ('ab','fl','re','pp')
AND DAYOFWEEK(b.statusdate) = DAYOFWEEK(NOW())
AND (HOUR(b.statusdate)< HOUR(NOW()))
GROUP BY 1
ORDER BY 1 DESC
Thanks!
Ok, here's the deallio. To use TIME() you need MySQL 4.1.1+. Here's a quick fix that rounds to the nearest minute.
SELECT DATE_FORMAT(b.statusdate,'%Y-%m-%d, %a'), count(*), sum(payment)
FROM investreq a, reqstatus b
WHERE a.refnum = b.refnum AND b.status = 'ab'
AND a.curstatus NOT IN ('ab','fl','re','pp')
AND DAYOFWEEK(b.statusdate) = DAYOFWEEK(NOW())
AND (HOUR(b.statusdate)< HOUR(NOW()))
AND (MINUTE(b.statusdate)< MINUTE(NOW()))
GROUP BY 1
ORDER BY 1 DESC
AND (SECOND(b.statusdate)< SECOND(NOW()))