To answer why you're getting a Monday and not a Sunday:

You're adding a number of weeks to the date 0. What is date 0? 1900-01-01. What was the day on 1900-01-01? Monday. So in your code you're saying, how many weeks have passed since Monday, January 1, 1900? Let's call that [n]. Ok, now add [n] weeks to Monday, January 1, 1900. You should not be surprised that this ends up being a Monday. DATEADD has no idea that you want to add weeks but only until you get to a Sunday, it's just adding 7 days, then adding 7 more days, ... just like DATEDIFF only recognizes boundaries that have been crossed. For example, these both return 1, even though some folks complain that there should be some sensible logic built in to round up or down:

SELECT DATEDIFF(YEAR, '2010-01-01', '2011-12-31');
SELECT DATEDIFF(YEAR, '2010-12-31', '2011-01-01');

To answer how to get a Sunday:

If you want a Sunday, then pick a base date that's not a Monday but rather a Sunday. For example:

DECLARE @dt DATE = '1905-01-01';
SELECT [start_of_week] = DATEADD(WEEK, DATEDIFF(WEEK, @dt, CURRENT_TIMESTAMP), @dt);

This will not break if you change your DATEFIRST setting (or your code is running for a user with a different setting) - provided that you still want a Sunday regardless of the current setting. If you want those two answers to jive, then you should use a function that does depend on the DATEFIRST setting, e.g.

SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, CURRENT_TIMESTAMP), CURRENT_TIMESTAMP);

So if you change your DATEFIRST setting to Monday, Tuesday, what have you, the behavior will change. Depending on which behavior you want, you could use one of these functions:

CREATE FUNCTION dbo.StartOfWeek1 -- always a Sunday
(
    @d DATE
)
RETURNS DATE
AS
BEGIN
    RETURN (SELECT DATEADD(WEEK, DATEDIFF(WEEK, '19050101', @d), '19050101'));
END
GO

...or...

CREATE FUNCTION dbo.StartOfWeek2 -- always the DATEFIRST weekday
(
    @d DATE
)
RETURNS DATE
AS
BEGIN
    RETURN (SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, @d), @d));
END
GO

Now, you have plenty of alternatives, but which one performs best? I'd be surprised if there would be any major differences but I collected all the answers provided so far and ran them through two sets of tests - one cheap and one expensive. I measured client statistics because I don't see I/O or memory playing a part in the performance here (though those may come into play depending on how the function is used). In my tests the results are:

"Cheap" assignment query:

Function - client processing time / wait time on server replies / total exec time
Gandarez     - 330/2029/2359 - 0:23.6
me datefirst - 329/2123/2452 - 0:24.5
me Sunday    - 357/2158/2515 - 0:25.2
trailmax     - 364/2160/2524 - 0:25.2
Curt         - 424/2202/2626 - 0:26.3

"Expensive" assignment query:

Function - client processing time / wait time on server replies / total exec time
Curt         - 1003/134158/135054 - 2:15
Gandarez     -  957/142919/143876 - 2:24
me Sunday    -  932/166817/165885 - 2:47
me datefirst -  939/171698/172637 - 2:53
trailmax     -  958/173174/174132 - 2:54

I can relay the details of my tests if desired - stopping here as this is already getting quite long-winded. I was a bit surprised to see Curt's come out as the fastest at the high end, given the number of calculations and inline code. Maybe I'll run some more thorough tests and blog about it... if you guys don't have any objections to me publishing your functions elsewhere.


If you're lucky enough to be on SQL Server 2022 or better (or Azure SQL Database / MI), you can use two new functions:

  • DATETRUNC
  • DATE_BUCKET

They are similarly affected by @@DATEFIRST settings, so you have to work around those. Actually DATETRUNC doesn't really offer any benefit unless you know you will always be in SET DATEFIRST 7 - you can make it work like the other workarounds here, but it's not any less complicated to do so. So, let's focus on DATE_BUCKET(). For February 2025, we want the first day of the week to be February 2nd, February 9th, and so on.

DECLARE @d table(d date);

INSERT @d SELECT d = dateadd(DAY, value, '20250201')
  FROM GENERATE_SERIES(0, 10);

-- I want Sunday as week boundary!
-- with default datefirst for 'merika: 7
  
  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- wrong! based on Jan 1, 1900
    datetrnc_right = DATETRUNC(WEEK,d), -- correct
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

-- even if someone made it Monday (or any other day!)

SET DATEFIRST 1;

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- still wrong
    datetrnc_wrong = DATETRUNC(WEEK,d), -- wrong!
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

d wd wdn datebuck_wrong datetrnc_right oldapproach
2025-02-01 7 Saturday 2025-01-27 2025-01-26 2025-01-26
2025-02-02 1 Sunday 2025-01-27 2025-02-02 2025-02-02
2025-02-03 2 Monday 2025-02-03 2025-02-02 2025-02-02
2025-02-04 3 Tuesday 2025-02-03 2025-02-02 2025-02-02
2025-02-05 4 Wednesday 2025-02-03 2025-02-02 2025-02-02
2025-02-06 5 Thursday 2025-02-03 2025-02-02 2025-02-02
2025-02-07 6 Friday 2025-02-03 2025-02-02 2025-02-02
2025-02-08 7 Saturday 2025-02-03 2025-02-02 2025-02-02
2025-02-09 1 Sunday 2025-02-03 2025-02-09 2025-02-09
2025-02-10 2 Monday 2025-02-10 2025-02-09 2025-02-09
2025-02-11 3 Tuesday 2025-02-10 2025-02-09 2025-02-09
d wd wdn datebuck_wrong datetrnc_wrong oldapproach
2025-02-01 6 Saturday 2025-01-27 2025-01-27 2025-01-26
2025-02-02 7 Sunday 2025-01-27 2025-01-27 2025-02-02
2025-02-03 1 Monday 2025-02-03 2025-02-03 2025-02-02
2025-02-04 2 Tuesday 2025-02-03 2025-02-03 2025-02-02
2025-02-05 3 Wednesday 2025-02-03 2025-02-03 2025-02-02
2025-02-06 4 Thursday 2025-02-03 2025-02-03 2025-02-02
2025-02-07 5 Friday 2025-02-03 2025-02-03 2025-02-02
2025-02-08 6 Saturday 2025-02-03 2025-02-03 2025-02-02
2025-02-09 7 Sunday 2025-02-03 2025-02-03 2025-02-09
2025-02-10 1 Monday 2025-02-10 2025-02-10 2025-02-09
2025-02-11 2 Tuesday 2025-02-10 2025-02-10 2025-02-09
  • db<>fiddle

We can coerce DATE_BUCKET() to work as we want by simply providing its optional fourth parameter - origin - any known Sunday, like the trick we used above with 1905-01-01. December 1st, 2024 was a Sunday, so we can use that:

DECLARE @d table(d date);

DECLARE  @origin_date date = '20241201'; -- known Sunday

INSERT @d SELECT d = dateadd(DAY, value, '20250201')
  FROM GENERATE_SERIES(0, 10);

-- I want Sunday as week boundary!
-- with default datefirst for 'merika: 7

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- wrong! based on Jan 1, 1900
    /* added: */
    datebuck_origin = DATE_BUCKET(WEEK, 1, d, @origin_date),
    datetrnc_right = DATETRUNC(WEEK,d), -- correct
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

-- even if someone made it Monday (or any other day!)
SET DATEFIRST 1;

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck = DATE_BUCKET(WEEK, 1, d), -- still wrong
    /* added: */
    datebuck_origin = DATE_BUCKET(WEEK, 1, d, @origin_date),
    datetrnc_wrong = DATETRUNC(WEEK,d), -- wrong!
    datefrst = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;
d wd wdn datebuck_wrong datebuck_origin_right datetrnc_right oldapproach
2025-02-01 7 Saturday 2025-01-27 2025-01-26 2025-01-26 2025-01-26
2025-02-02 1 Sunday 2025-01-27 2025-02-02 2025-02-02 2025-02-02
2025-02-03 2 Monday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-04 3 Tuesday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-05 4 Wednesday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-06 5 Thursday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-07 6 Friday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-08 7 Saturday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-09 1 Sunday 2025-02-03 2025-02-09 2025-02-09 2025-02-09
2025-02-10 2 Monday 2025-02-10 2025-02-09 2025-02-09 2025-02-09
2025-02-11 3 Tuesday 2025-02-10 2025-02-09 2025-02-09 2025-02-09
d wd wdn datebuck datebuck_origin_right datetrnc datefrst
2025-02-01 6 Saturday 2025-01-27 2025-01-26 2025-01-27 2025-01-26
2025-02-02 7 Sunday 2025-01-27 2025-02-02 2025-01-27 2025-02-02
2025-02-03 1 Monday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-04 2 Tuesday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-05 3 Wednesday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-06 4 Thursday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-07 5 Friday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-08 6 Saturday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-09 7 Sunday 2025-02-03 2025-02-09 2025-02-03 2025-02-09
2025-02-10 1 Monday 2025-02-10 2025-02-09 2025-02-10 2025-02-09
2025-02-11 2 Tuesday 2025-02-10 2025-02-09 2025-02-10 2025-02-09
  • db<>fiddle

You might say, "Why not just manually hard-code SET DATEFIRST?" Well, that can't be done inside functions, for example, and also you can't just override users' settings who may be relying on the existing setting for other behaviors.

Answer from Aaron Bertrand on Stack Overflow
🌐
LearnSQL.com
learnsql.com › blog › how-to-datepart-sql-server
How to Get the First Day of the Week in SQL Server | LearnSQL.com
April 2, 2020 - How to display the first day of the week in SQL Server using Sunday as the start of the week, Monday as the start of the week, or the DATEFIRST field
Top answer
1 of 16
165

To answer why you're getting a Monday and not a Sunday:

You're adding a number of weeks to the date 0. What is date 0? 1900-01-01. What was the day on 1900-01-01? Monday. So in your code you're saying, how many weeks have passed since Monday, January 1, 1900? Let's call that [n]. Ok, now add [n] weeks to Monday, January 1, 1900. You should not be surprised that this ends up being a Monday. DATEADD has no idea that you want to add weeks but only until you get to a Sunday, it's just adding 7 days, then adding 7 more days, ... just like DATEDIFF only recognizes boundaries that have been crossed. For example, these both return 1, even though some folks complain that there should be some sensible logic built in to round up or down:

SELECT DATEDIFF(YEAR, '2010-01-01', '2011-12-31');
SELECT DATEDIFF(YEAR, '2010-12-31', '2011-01-01');

To answer how to get a Sunday:

If you want a Sunday, then pick a base date that's not a Monday but rather a Sunday. For example:

DECLARE @dt DATE = '1905-01-01';
SELECT [start_of_week] = DATEADD(WEEK, DATEDIFF(WEEK, @dt, CURRENT_TIMESTAMP), @dt);

This will not break if you change your DATEFIRST setting (or your code is running for a user with a different setting) - provided that you still want a Sunday regardless of the current setting. If you want those two answers to jive, then you should use a function that does depend on the DATEFIRST setting, e.g.

SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, CURRENT_TIMESTAMP), CURRENT_TIMESTAMP);

So if you change your DATEFIRST setting to Monday, Tuesday, what have you, the behavior will change. Depending on which behavior you want, you could use one of these functions:

CREATE FUNCTION dbo.StartOfWeek1 -- always a Sunday
(
    @d DATE
)
RETURNS DATE
AS
BEGIN
    RETURN (SELECT DATEADD(WEEK, DATEDIFF(WEEK, '19050101', @d), '19050101'));
END
GO

...or...

CREATE FUNCTION dbo.StartOfWeek2 -- always the DATEFIRST weekday
(
    @d DATE
)
RETURNS DATE
AS
BEGIN
    RETURN (SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, @d), @d));
END
GO

Now, you have plenty of alternatives, but which one performs best? I'd be surprised if there would be any major differences but I collected all the answers provided so far and ran them through two sets of tests - one cheap and one expensive. I measured client statistics because I don't see I/O or memory playing a part in the performance here (though those may come into play depending on how the function is used). In my tests the results are:

"Cheap" assignment query:

Function - client processing time / wait time on server replies / total exec time
Gandarez     - 330/2029/2359 - 0:23.6
me datefirst - 329/2123/2452 - 0:24.5
me Sunday    - 357/2158/2515 - 0:25.2
trailmax     - 364/2160/2524 - 0:25.2
Curt         - 424/2202/2626 - 0:26.3

"Expensive" assignment query:

Function - client processing time / wait time on server replies / total exec time
Curt         - 1003/134158/135054 - 2:15
Gandarez     -  957/142919/143876 - 2:24
me Sunday    -  932/166817/165885 - 2:47
me datefirst -  939/171698/172637 - 2:53
trailmax     -  958/173174/174132 - 2:54

I can relay the details of my tests if desired - stopping here as this is already getting quite long-winded. I was a bit surprised to see Curt's come out as the fastest at the high end, given the number of calculations and inline code. Maybe I'll run some more thorough tests and blog about it... if you guys don't have any objections to me publishing your functions elsewhere.


If you're lucky enough to be on SQL Server 2022 or better (or Azure SQL Database / MI), you can use two new functions:

  • DATETRUNC
  • DATE_BUCKET

They are similarly affected by @@DATEFIRST settings, so you have to work around those. Actually DATETRUNC doesn't really offer any benefit unless you know you will always be in SET DATEFIRST 7 - you can make it work like the other workarounds here, but it's not any less complicated to do so. So, let's focus on DATE_BUCKET(). For February 2025, we want the first day of the week to be February 2nd, February 9th, and so on.

DECLARE @d table(d date);

INSERT @d SELECT d = dateadd(DAY, value, '20250201')
  FROM GENERATE_SERIES(0, 10);

-- I want Sunday as week boundary!
-- with default datefirst for 'merika: 7
  
  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- wrong! based on Jan 1, 1900
    datetrnc_right = DATETRUNC(WEEK,d), -- correct
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

-- even if someone made it Monday (or any other day!)

SET DATEFIRST 1;

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- still wrong
    datetrnc_wrong = DATETRUNC(WEEK,d), -- wrong!
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

d wd wdn datebuck_wrong datetrnc_right oldapproach
2025-02-01 7 Saturday 2025-01-27 2025-01-26 2025-01-26
2025-02-02 1 Sunday 2025-01-27 2025-02-02 2025-02-02
2025-02-03 2 Monday 2025-02-03 2025-02-02 2025-02-02
2025-02-04 3 Tuesday 2025-02-03 2025-02-02 2025-02-02
2025-02-05 4 Wednesday 2025-02-03 2025-02-02 2025-02-02
2025-02-06 5 Thursday 2025-02-03 2025-02-02 2025-02-02
2025-02-07 6 Friday 2025-02-03 2025-02-02 2025-02-02
2025-02-08 7 Saturday 2025-02-03 2025-02-02 2025-02-02
2025-02-09 1 Sunday 2025-02-03 2025-02-09 2025-02-09
2025-02-10 2 Monday 2025-02-10 2025-02-09 2025-02-09
2025-02-11 3 Tuesday 2025-02-10 2025-02-09 2025-02-09
d wd wdn datebuck_wrong datetrnc_wrong oldapproach
2025-02-01 6 Saturday 2025-01-27 2025-01-27 2025-01-26
2025-02-02 7 Sunday 2025-01-27 2025-01-27 2025-02-02
2025-02-03 1 Monday 2025-02-03 2025-02-03 2025-02-02
2025-02-04 2 Tuesday 2025-02-03 2025-02-03 2025-02-02
2025-02-05 3 Wednesday 2025-02-03 2025-02-03 2025-02-02
2025-02-06 4 Thursday 2025-02-03 2025-02-03 2025-02-02
2025-02-07 5 Friday 2025-02-03 2025-02-03 2025-02-02
2025-02-08 6 Saturday 2025-02-03 2025-02-03 2025-02-02
2025-02-09 7 Sunday 2025-02-03 2025-02-03 2025-02-09
2025-02-10 1 Monday 2025-02-10 2025-02-10 2025-02-09
2025-02-11 2 Tuesday 2025-02-10 2025-02-10 2025-02-09
  • db<>fiddle

We can coerce DATE_BUCKET() to work as we want by simply providing its optional fourth parameter - origin - any known Sunday, like the trick we used above with 1905-01-01. December 1st, 2024 was a Sunday, so we can use that:

DECLARE @d table(d date);

DECLARE  @origin_date date = '20241201'; -- known Sunday

INSERT @d SELECT d = dateadd(DAY, value, '20250201')
  FROM GENERATE_SERIES(0, 10);

-- I want Sunday as week boundary!
-- with default datefirst for 'merika: 7

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck_wrong = DATE_BUCKET(WEEK, 1, d), -- wrong! based on Jan 1, 1900
    /* added: */
    datebuck_origin = DATE_BUCKET(WEEK, 1, d, @origin_date),
    datetrnc_right = DATETRUNC(WEEK,d), -- correct
    oldapproach = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;

-- even if someone made it Monday (or any other day!)
SET DATEFIRST 1;

  SELECT
    d,
    wd  = DATEPART(WEEKDAY, d),
    wdn = DATENAME(WEEKDAY, d),
    datebuck = DATE_BUCKET(WEEK, 1, d), -- still wrong
    /* added: */
    datebuck_origin = DATE_BUCKET(WEEK, 1, d, @origin_date),
    datetrnc_wrong = DATETRUNC(WEEK,d), -- wrong!
    datefrst = DATEADD(DAY, -(DATEPART(WEEKDAY, d) + @@DATEFIRST + 6)%7, d)
  FROM @d;
d wd wdn datebuck_wrong datebuck_origin_right datetrnc_right oldapproach
2025-02-01 7 Saturday 2025-01-27 2025-01-26 2025-01-26 2025-01-26
2025-02-02 1 Sunday 2025-01-27 2025-02-02 2025-02-02 2025-02-02
2025-02-03 2 Monday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-04 3 Tuesday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-05 4 Wednesday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-06 5 Thursday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-07 6 Friday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-08 7 Saturday 2025-02-03 2025-02-02 2025-02-02 2025-02-02
2025-02-09 1 Sunday 2025-02-03 2025-02-09 2025-02-09 2025-02-09
2025-02-10 2 Monday 2025-02-10 2025-02-09 2025-02-09 2025-02-09
2025-02-11 3 Tuesday 2025-02-10 2025-02-09 2025-02-09 2025-02-09
d wd wdn datebuck datebuck_origin_right datetrnc datefrst
2025-02-01 6 Saturday 2025-01-27 2025-01-26 2025-01-27 2025-01-26
2025-02-02 7 Sunday 2025-01-27 2025-02-02 2025-01-27 2025-02-02
2025-02-03 1 Monday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-04 2 Tuesday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-05 3 Wednesday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-06 4 Thursday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-07 5 Friday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-08 6 Saturday 2025-02-03 2025-02-02 2025-02-03 2025-02-02
2025-02-09 7 Sunday 2025-02-03 2025-02-09 2025-02-03 2025-02-09
2025-02-10 1 Monday 2025-02-10 2025-02-09 2025-02-10 2025-02-09
2025-02-11 2 Tuesday 2025-02-10 2025-02-09 2025-02-10 2025-02-09
  • db<>fiddle

You might say, "Why not just manually hard-code SET DATEFIRST?" Well, that can't be done inside functions, for example, and also you can't just override users' settings who may be relying on the existing setting for other behaviors.

2 of 16
23

For these that need to get:

Monday = 1 and Sunday = 7:

SELECT 1 + ((5 + DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7);

Sunday = 1 and Saturday = 7:

SELECT 1 + ((6 + DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7);

Above there was a similar example, but thanks to double "%7" it would be much slower.

Discussions

Get first day of week from WEEK() function, or alternatives
I’d suggest importing and using date dim table, helps massively with things like that More on reddit.com
🌐 r/SQL
7
2
April 19, 2023
Query to find the start day of the week as Monday – SQLServerCentral Forums
Query to find the start day of the week as Monday Forum – Learn more on SQLServerCentral More on sqlservercentral.com
🌐 sqlservercentral.com
December 4, 2012
t sql - Get first day of week T-SQL - Stack Overflow
How get first day of week (Monday) where week = 6 and year = 2020 I need get 10.02.2020 eg. week 1 in 2020 is date from 06.01.2020 - 12.01.2020 week 6 in 2020 is date from 10.02.2020 - 16.02.2020 More on stackoverflow.com
🌐 stackoverflow.com
How to get first day of the week and last day of the week in sql server 2008? - Stack Overflow
How to get the first day of the week and last day of the week when we input any one day of a week? For example if we enter a date then the first(Monday) and last (Friday) day should be displayed. ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
SQLServerCentral
sqlservercentral.com › articles › how-to-find-the-start-and-end-dates-for-the-current-week-and-more
How to Find the Start and End Dates for the Current Week (and more) – SQLServerCentral
July 13, 2022 - Then, we’ll take the difference ... week that our "given date" is in. After that, simple subtraction (again, using DATEADD()) will tell us the date of the first of the week....
🌐
Reddit
reddit.com › r/sql › get first day of week from week() function, or alternatives
r/SQL on Reddit: Get first day of week from WEEK() function, or alternatives
April 19, 2023 -

Is there a way to get the start date of a week using the WEEK() function rather than an integer representing the number of the week in the year? I know there's easy enough ways to manipulate this manually but it would be nice to output it simply.

🌐
C# Corner
c-sharpcorner.com › blogs › get-week-start-date-week-end-date-using-sql-server
Get Week Start Date & Week End Date Using SQL Server
November 17, 2023 - Datepart is a part of date, e.g. day, month, year. ... Returns the current database system timestamp as a datetime value. This value is derived from the operating system of the computer on which the instance of SQL Server is running. ... Converts an expression of one data type to another. ... select DATEPART(WEEKDAY, GETDATE()) select CAST(GETDATE() AS DATE) SELECT DATEADD(DAY, 2 - 5, '2017-04-06') [Week_Start_Date]
🌐
YouTube
youtube.com › watch
Calculating the first day of the week in SQL Server - YouTube
How can you find the start of a week?My SQL Server Udemy courses are:70-461, 70-761 Querying Microsoft SQL Server with T-SQL: https://rebrand.ly/querying-mic...
Published   February 24, 2022
🌐
Sql-server-helper
sql-server-helper.com › functions › get-first-day-of-week.aspx
SQL Server Helper - Get First Day of the Week Function
It is quite common for applications ... Getting the current day is easy because this is achieved from the GETDATE() function but getting the start of the week is a little bit tricky. The user-defined function below accepts a date input and returns the first day of the week for that ...
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › statements › set-datefirst-transact-sql
SET DATEFIRST (Transact-SQL) - SQL Server | Microsoft Learn
November 18, 2025 - -- SET DATEFIRST to U.S. English default value of 7. SET DATEFIRST 7; SELECT CAST('1999-1-1' AS datetime2) AS SelectDate ,DATEPART(dw, '1999-1-1') AS DayOfWeek; -- January 1, 1999 is a Friday. Because the U.S. English default -- specifies Sunday as the first day of the week, DATEPART of 1999-1-1 -- (Friday) yields a value of 6, because Friday is the sixth day of the -- week when you start with Sunday as day 1.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › query-to-find-the-start-day-of-the-week-as-monday
Query to find the start day of the week as Monday – SQLServerCentral Forums
December 4, 2012 - Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/ Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/ Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/ Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/ ... Thanks for the reply. I used the below case statement in my Select statement to get the starting day as Monday:
🌐
GeeksforGeeks
geeksforgeeks.org › sql › sql-query-to-get-first-and-last-day-of-a-week-in-a-database
SQL Query to Get First and Last Day of a Week in a Database - GeeksforGeeks
May 9, 2021 - /* If you want to find out the first day of upcoming weeks then set @weeks as a positive integer with number of weeks, else negative integer. */ DECLARE @weeks integer; SET @weeks = 1; SELECT DATEADD(WEEK, @weeks, DATEADD(DAY, 1-DATEPART(WEEKDAY, ...
🌐
W3Schools
w3schools.com › sql › func_mysql_week.asp
MySQL WEEK() Function
The WEEK() function returns the week number for a given date (a number from 0 to 53). ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report ...
🌐
SQLTeam
forums.sqlteam.com › transact-sql
Create a Select to select the first day of the week (Monday) in each week of the financial year - Transact-SQL - SQLTeam.com Forums
July 13, 2021 - Hi, I need to create a report that shows the first weekday in each week for 52 weeks (we ignore any extra days). Is there a way to do a select statement to show 52 results, each with a different starting day? e.g. 05/…
🌐
Microsoft Technet
social.technet.microsoft.com › wiki › contents › articles › 52338.sql-server-get-week-start-date-week-end-date-using-sql-query.aspx
SQL Server: Get Week Start Date & Week End Date Using Sql Query | Microsoft Learn
December 29, 2018 - CAST() Converts an expression of one data type to another. ... select DATEPART(WEEKDAY, GETDATE()) select CAST(GETDATE() AS DATE) SELECT DATEADD(DAY, 2 - 5, '2017-04-06') [Week_Start_Date]
🌐
Tutorialsrack
tutorialsrack.com › articles › 62 › how-to-get-first-and-last-day-of-a-week-in-sql-server
How to Get First and Last Day of a Week in SQL Server
First Day of the Current Week -------------------------------------- 2019-04-21 00:00:00.000 · To get the last day of the current week in SQL Server, a statement is as follow: