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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:56:55+00:00 2026-05-30T13:56:55+00:00

Using the syntax dateadd(week, datediff(week, 0, CURRENT_TIMESTAMP),0) to group data by week it appears

  • 0

Using the syntax

dateadd(week, datediff(week, 0, CURRENT_TIMESTAMP),0)

to group data by week it appears that the last day of the week gets put into the following week.

In a simple example

print dateadd(week, datediff(week, 0, '27 jan 2012 00:00'),0)
print dateadd(week, datediff(week, 0, '28 jan 2012 00:00'),0)
print dateadd(week, datediff(week, 0, '29 jan 2012 00:00'),0)
print dateadd(week, datediff(week, 0, '30 jan 2012 00:00'),0)
print dateadd(week, datediff(week, 0, '31 jan 2012 00:00'),0)

I would expect to return

Jan 23 2012 12:00AM
Jan 23 2012 12:00AM
Jan 23 2012 12:00AM
Jan 30 2012 12:00AM
Jan 30 2012 12:00AM

or

Jan 22 2012 12:00AM
Jan 22 2012 12:00AM
Jan 29 2012 12:00AM
Jan 29 2012 12:00AM
Jan 29 2012 12:00AM

depending on DATEFIRST settings I guess

however it returns

Jan 23 2012 12:00AM
Jan 23 2012 12:00AM
Jan 30 2012 12:00AM
Jan 30 2012 12:00AM
Jan 30 2012 12:00AM

i.e. the 29 January is in the week of 30th January not 23rd January or 30th January as expected.

I’m clearly missing something but can’t think what it might be.

  • 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-05-30T13:56:56+00:00Added an answer on May 30, 2026 at 1:56 pm

    This is correct.

    No matter what @@DATEFIRST is, there is always the same number of whole weeks between now and 01 Jan 1900. As @@DATEFIRST changes, it affects both “start” and “end” week.

    DATEADD then just adds 7 day periods because it ignores @@DATEFIRST

    You can force it by choosing the DATEADD base

    Example: 01 Jan 1900 is a Monday.

    You want Sunday? Then base to 31 Dec 1899

    print dateadd(week, datediff(week, 0, '27 jan 2012 00:00'),-1)
    print dateadd(week, datediff(week, 0, '28 jan 2012 00:00'),-1)
    print dateadd(week, datediff(week, 0, '29 jan 2012 00:00'),-1)
    print dateadd(week, datediff(week, 0, '30 jan 2012 00:00'),-1)
    print dateadd(week, datediff(week, 0, '31 jan 2012 00:00'),-1)
    

    You want Tuesday? Then base to 02 Jan 1900

    print dateadd(week, datediff(week, 0, '27 jan 2012 00:00'),1)
    print dateadd(week, datediff(week, 0, '28 jan 2012 00:00'),1)
    print dateadd(week, datediff(week, 0, '29 jan 2012 00:00'),1)
    print dateadd(week, datediff(week, 0, '30 jan 2012 00:00'),1)
    print dateadd(week, datediff(week, 0, '31 jan 2012 00:00'),1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding is that the LinqToSql pseudolanguage describes a set using a syntax very
I've embedded a SWF into a class using this syntax above my class definition:
Using this syntax: var position = array($('#ipadmenu > section').attr('data-order')); I cannot get my code
I found problem when trying to retrieve specific name column that using syntax/statement/command using
Using MySQL syntax and having a table with a row like: mydate DATETIME NULL,
Using MySQL syntax, how would I write a query to return the following (I
Using extension syntax I'm trying to create a left-join using LINQ on two lists
What's the point using this syntax div.card > div.name What's the difference between this
Is it possible to use the syntax using(_mocks.Record()) { //... } using(_mocks.Playback()) { //...
I am trying to create a multi dimensional array using this syntax: $x[1] =

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.