| |

VerySource

 Forgot password?
 Register
Search
View: 879|Reply: 6

Knowing the week of a year, how to find the first and last day of the week?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-18 01:30:01
| Show all posts |Read mode
If you know the first week of 2017, how do you find the first and last day of the week?

For example: 2017, the first week, get the following expression
---------------------------------------
2016-12-31 00: 00: 00.000
2017-01-06 00: 00: 00.000


In 2017, the second week, I got the following expression
---------------------------------------
2017-01-07 00: 00: 00.000
2017-01-13 00: 00: 00.000


Eager for advice, thank you
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-6-21 19:45:01
| Show all posts
select top 1 field from (known record set order by field ASC)-the first day
select top 1 field from (known record set order by field DESC)-last day
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-22 11:45:01
| Show all posts
declare @year int,@week int,@day datetime
select @year = 2017,@week = 3,@day = convert(char(4),@year) + '0101'
select dateadd(day,(@week-1)*7 -datepart(week,@day),@day) as the first day, dateadd(day,(@week-1)*7+6-datepart(week,@ day),@day) as the last day
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-23 00:45:01
| Show all posts
declare @year int, @week int
select @year = 2017, @week = 1
select dateadd(day, @week * 7-datepart(weekday, dateadd(year, @year-1900, 0))-6, dateadd(year, @year-1900, 0)),
       dateadd(day, @week * 7-datepart(weekday, dateadd(year, @year-1900, 0)) + 1, dateadd(year, @year-1900, 0))
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-6-23 12:00:02
| Show all posts
From a known first and last day datepart(weekday,,)
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-25 17:15:01
| Show all posts
Thank youzy_1306

sinexesinexewill do, just the first day of the week is Sunday, thank you all
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-25 19:00:02
| Show all posts
Only the first day of the week is Sunday
-------------
This is it
First day last day
-------------------------------------------------- ---- ---------------------------------------------- --------
2016-12-31 00:00:00.000 2017-01-06 00:00:00.000

(The number of rows affected is 1 row)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list