Hi @Analyst_SQL
If I understand correctly, you can give it a try.
select dateTimes,case when datepart(mi,dateTimes) >= 45 then
DATEADD(minute, (DATEDIFF(minute, 0, DATEADD(second, 15 * 60, dateTimes)) / 15) * 15, 0)
else dateTimes end as dateTimeRoundNear
from test;
I have tested it.
create table test(dateTimes datetime);
insert into test values
('18:00'),('18:10'),('18:15'),('18:20'),('18:30'),
('18:35'),('18:40'),('18:42'),('18:44'),('18:45'),
('18:46'),('18:59'),('19:44'),('19:45'),('19:46');
output:
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.