Home > database >  SQL server according to the start time and end time for every day
SQL server according to the start time and end time for every day

Time:11-23

Example: the start time: 2020-05-01 end time: 2020-05-01

Results:
The 2020-05-01
The 2020-05-02
The 2020-05-03
The 2020-05-04
The 2020-05-05

CodePudding user response:

What are the useful function can support

CodePudding user response:

 declare @ time1 datetime, @ time2 datetime 
The set @ time1=getdate ()
The set @ time2=DATEADD (DAY 5, getdate ())
Select @ time1, @ time2

/* result
The 2020-05-15 15:18:56. 990 2020-05-20 15:18:56. 990 */

The select DATEADD (DAY, number, @ time1) from the master.. Spt_values
Where type='P' and number between 0 and DATEDIFF (DAY, @ time1, @ time2)
/* result
The 2020-05-15 15:18:56. 990
The 2020-05-16 15:18:56. 990
The 2020-05-17 15:18:56. 990
The 2020-05-18 15:18:56. 990
The 2020-05-19 15:18:56. 990
The 2020-05-20 15:18:56. 990 */
  • Related