SELECT DATEADD(MINUTE, CEILING(DATEDIFF(SECOND, 0, CAST(CAST(PA.ORA_INIZIO AS DATETIME) AS TIME)) / 60.0), DATEDIFF(DAY, 0, PA.ORA_INIZIO)) AS BEGIN_TIME_ROUNDED
UPRAVIT
Jak je zdůrazněno v komentáři, toto selže pro časy mezi 0 a 1 sekundou. Tomu lze zabránit jednoduchou změnou přesnosti stropu ze sekund na milisekundy:
SELECT PA.ORA_INIZIO,
DATEADD(MINUTE,
CEILING(DATEDIFF(MILLISECOND, 0, CAST(PA.ORA_INIZIO AS TIME)) / 60000.0),
DATEDIFF(DAY, 0, PA.ORA_INIZIO)) AS BEGIN_TIME_ROUNDED
FROM (VALUES
(CONVERT(DATETIME, '20211126 15:59:00.997')),
(CONVERT(DATETIME, '20211126 15:59:00.004'))
) AS PA (ORA_INIZIO);
Což dává:
ORA_INIZIO | BEGIN_TIME_ROUNDED |
---|---|
26. 11. 2021 15:59:59.997 | 26. 11. 2021 16:00:00 000 |
26. 11. 2021 15:59:00.003 | 26. 11. 2021 16:00:00 000 |