Get current week

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Get current week

Post by GeXus »

I'm trying to do a query to get items that fall within the current week... This is the query i'm using

Code: Select all

 
 
SELECT a.id, a.name, a.description, a.category_id, a.language_id, a.guid from quizzes a
inner join quiz_ratings b on a.id = b.quiz_id
where a.active = '1' and YEARWEEK(b.created_dt) = YEARWEEK(CURRENT_DATE - INTERVAL 7 DAY)
 
 
This doesn't work though, it returns zero results, but created_dt has date stamps for today..

Any ideas? Thanks!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Get current week

Post by Kieran Huggins »

try:

Code: Select all

SELECT a.id, a.name, a.description, a.category_id, a.language_id, a.guid 
FROM quizzes AS a
INNER JOIN quiz_ratings AS b ON a.id = b.quiz_id
WHERE a.active = '1' 
AND YEARWEEK(DATE_SUB(CURDATE(),INTERVAL 15 DAY)) >= YEARWEEK(b.created_dt);
Post Reply