There are two variables of the DateTime values available: for example, @STARTDATETIME = '2020-10-21 14:45' and @ENDDATETIME = '2020-10-22 19:00'
If there is only a single day between dates like STARTDATETIME = '2020-10-21 12:00' and ENDDATETIME = '2020-10-21 16:00' then the variables must save the initial values.
If there are one or more days between the values then the first date must start with the given timestamp to 16:00. The all in-between days time must be as from 08:00 till 16:00. And the last day must start with 08:00 time till the given timestamp.
Full example:
@STARTDATETIME = '2020-10-21 14:45' and @ENDDATETIME = '2020-10-23 19:15'
Desired output (table):
STARTDATETIME | ENDDATETIME
'2020-10-21 14:45' | '2020-10-21 16:00'
'2020-10-22 08:00' | '2020-10-22 16:00'
'2020-10-23 08:00' | '2020-10-23 19:15'