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 9091401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:36:03+00:00 2026-06-16T22:36:03+00:00

I need to fetch all records from current week. But since Monday Dec 31st

  • 0

I need to fetch all records from current week. But since Monday Dec 31st was in 2012, mysql treats it as week 53, instead of week 1 of 2013. How can I get around that?

Query:

SELECT COUNT(*) AS `cnt`
FROM `orders`
WHERE WEEK(`date_purchased`, 1) = WEEK(NOW(), 1)
    AND (
           (
            MONTH(`date_purchased`) = MONTH(NOW() - INTERVAL 1 WEEK)
            AND YEAR(`date_purchased`) = YEAR(NOW() - INTERVAL 1 WEEK)
            )
        OR (
            MONTH(`date_purchased`) = MONTH(NOW())
            AND YEAR(`date_purchased`) = YEAR(NOW())
            )
        )
  • 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-16T22:36:04+00:00Added an answer on June 16, 2026 at 10:36 pm

    According to ISO standard, week number 1 of the year is the first week with the majority of its days in the starting year, and while week(date,1) returns week 53 for ‘2012-12-31’, week(date,3) or its equivalent weekofyear(date) correctly return week number according to this standard, so:

    weekofyear('2013-01-01') = weekofyear('2012-12-31') = 1
    -- week starts on Monday, and 2012-12-31 is part of the first week of 2013
    
    weekofyear('2012-01-01') = weekofyear('2011-12-31') = 52
    -- last week of 2011 starts on 12-26, first week of 2012 starts on 01-02
    
    weekofyear('2010-01-01') = weekofyear('2009-12-31') = 53
    -- some years have 53 weeks
    
    weekofyear('2007-01-01') != weekofyear('2006-12-31')
    -- that's correct because the first day of 2007 was a Monday
    

    Since your request is more specific, if you have to check if two days are part of the same week of the same year, this is still not enough to answer your question.

    Instead of using week, or weekofyear, it’s better to use yearweek(date,mode) function, using mode=3, that returns the same week numbers as above, but also preceded by the year this week refers to:

    yearweek('2013-01-01', 3) = yearweek('2012-12-31', 3) = 201301
    yearweek('2012-01-01', 3) = yearweek('2011-12-31', 3) = 201152
    yearweek('2010-01-01', 3) = yearweek('2009-12-31', 3) = 200952
    yearweek('2007-01-01', 3) != yearweek('2006-12-31', 3)
    

    so your query could become:

    SELECT COUNT(*) AS `cnt`
    FROM `orders`
    WHERE YEARWEEK(`date_purchased`, 3) = YEARWEEK(DATE(), 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I need to fetch some records from the database, and filter them
I have two tables Member (member_id,...) friend-requests(member_id, friend_id) I need to fetch all records
The goal I need to achieve is to get all records from a cursor
I need to fetch 2 million records from the oracle database(1 year data). When
I need to fetch all email id's of contacts which is present in contact
I am creating a moderating application in which i need to fetch all the
I'm writing a simple web crawler in Ruby and I need to fetch all
I need to fetch data from normalized MSSQL db and feed them in Solr
Im using vb.net and I need to fetch data from two different tables and
I need your advice. I fetch data from database to table: ID, Name. In

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.