SQL Server How to Split the day hour in shiftwise? [closed]

1bqhqjot  于 2023-04-10  发布在  其他
关注(0)|答案(2)|浏览(132)

Closed. This question needs details or clarity . It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post .

Closed 4 years ago.
Improve this question

Can anyone say how to split the a day with 7 hours difference

Eg:

29/09/2018 00:00:00 -  29/09/2018 24:00:00

to

29/09/2018 07:00:00
29/09/2018 14:00:00
29/09/2018 21:00:00
xytpbqjk

xytpbqjk1#

You could use CROSS APPLY to make one row with a date column appear 3 times, each with a different time. This can be done like this:

SELECT t.SomeDate, hrs.SplitDateTIme
FROM SomeTable t
CROSS APPLY (
    VALUES 
        (DATEADD(hour, 5, t.SomeDate)),
        (DATEADD(hour, 12, t.SomeDate)),
        (DATEADD(hour, 19, t.SomeDate))
) AS hrs(SplitDateTime);
xoefb8l8

xoefb8l82#

If you are doing it in C# You can select a Start time of a day then add 7 hours to it

var date = DateTime.Now;
var date1 = date.AddHours(7);
var date2 = date1.AddHours(7);

Inform me is that what you want .

相关问题