| |

VerySource

 Forgot password?
 Register
Search
View: 685|Reply: 2

How to get a one-year timetable

[Copy link]

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-11-4 11:00:01
| Show all posts |Read mode
Create such a table
The contents of the table are the day before yesterday's date, today's date, tomorrow's date, today's week (such as Monday, Tuesday), today's week number (week function),
The key is to have one year of data after the establishment of this table
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-11-4 15:00:01
| Show all posts
Is it like this?

create table tb(yest datetime,today datetime,tomorrow datetime,weekname varchar(10),weeks int)
declare @day int,@dt datetime
set @day=0
set @dt='2016-01-02'
while @day<365
begin
insert tb select dateadd(day,@day,@dt),dateadd(day,@day+1,@dt),dateadd(day,@day+2,@dt),datename(dw,@dt+@day), datediff(week,@dt,dateadd(day,@day,@dt))+1
set @day=@day+1
end

select * from tb

drop table tb
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-11-4 16:15:01
| Show all posts
yes, very good!
Thank you upstairs
Unpost at night
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