Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9096879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:58:05+00:00 2026-06-16T23:58:05+00:00

This is part of my query: WHERE WEEK( data.time ) = ( WEEK( CURRENT_DATE

  • 0

This is part of my query:

WHERE WEEK( data.time ) = ( WEEK( CURRENT_DATE + INTERVAL -3 WEEK ) )

I can select data from three weeks ago, that means December 2012.
Now the problem is – I get data for that week for all years. Not just the one that has been three weeks ago.

Adding

YEAR( data.time ) = YEAR( CURRENT_DATE + INTERVAL -3 WEEK ) 

Solved the problem, but I wonder if it is necessary to compare the years also, or if I could stay with the week comparison only – if I adjust the first line somehow.

I’ve found similar query in here
MySQL week numbers and New Year
but they don’t mention such an issue with years and it seems it works for them even without year comparison.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:58:06+00:00Added an answer on June 16, 2026 at 11:58 pm

    You will be better served by comparing with the start and end of the required week. Something like:

    WHERE SUBDATE(CURDATE(), WEEKDAY(CURDATE()) + 21) <= data.time 
        AND data.time < SUBDATE(CURDATE(), WEEKDAY(CURDATE()) + 14);
    

    It will make a difference for the first and last week of the year. For example 2012-12-31 is part of 2013-W01 (first week of 2013). So WEEK would say 1 while YEAR would say 2012. Whereas for 2013-01-13, also part of 2013-W01 WEEK is 1 and YEAR is 2013. So naïve use of WEEK and YEAR for this will give you the wrong results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this part of a query SELECT * FROM conference WHERE active='1' AND
I'm looking at an execution plan from a troublesome query. I can see that
I have a query like this: SELECT X.Y( 'p1', 'p2', 'p3', 'p4', '100') FROM
i using this part of code to getting docs from sphinx but sphinx Query
I need to populate the combo box Items from a database query (this part
This query (part of a sproc) will be executed quite a lot: SELECT TOP
I have this data spited out from my cake php query.. This is the
So i have a query that is suppose to get me data from two
i have this Query : SELECT a.*, a.id AS id_player, (SELECT COUNT(id) FROM `vd7qw_footsal_goals`
I have written a subquery that goes like this: select top 1 A from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.