-2

by using GETDATE(),i can get current date and time like 2019-11-20 15:04:22 but i need next minute like 2019-11-20 15:05:00

Raj Paliwal
  • 943
  • 1
  • 9
  • 22
  • This is already answered.Please have a look. https://stackoverflow.com/questions/33760529/how-to-add-minutes-to-the-time-part-of-datetime – Its_Ady Nov 20 '19 at 15:59
  • 2
    Possible duplicate of [How to add minutes to the time part of datetime](https://stackoverflow.com/questions/33760529/how-to-add-minutes-to-the-time-part-of-datetime) – A. S. K. Nov 20 '19 at 16:00
  • in standard SQL this would be `current_timestamp + interval '1' minute` –  Nov 20 '19 at 20:51

2 Answers2

0
    CONVERT(DATETIME, CONVERT(SMALLDATETIME,
  DATEADD(minute, CASE WHEN d = CONVERT(SMALLDATETIME, d) THEN 0 ELSE 1 END,
  d)))

Taken from here: SQL Server - Round TIME values to the next minute

Yakir Malka
  • 308
  • 2
  • 11
0

One approach is to calculate the number of minutes since some point in time, add 1, and add that back to the original point in time.

0 is a convenient time for this purpose:

select dateadd(minute, datediff(minute, 0, dt) + 1, 0)
from (values (convert(datetime, '2019-11-20 15:04:22'))) v(dt)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786