I have an SQL script. I have a data in the column (date and time) and I would like to make a comparison: If the minutes are 5 from the current time, I will do an action. If I don't take another action.
The column in the table displays the data in (yyyyMMddhhmm). My comparison should be made only in minutes, in this case, 5.
I tried with DATEADD but no success.
Could anyone help?
CodePudding user response:
have you tried something like this ?
declare @test datetime = '20220414 10:05:00'
declare @test2 datetime = '20220414 10:14:00'
select @test,
@test2,
datediff(minute, @test, @test2) as minutesBetween
it returns this
COLUMN1 | COLUMN2 | minutesBetween |
---|---|---|
14/04/2022 10:05:00 | 14/04/2022 10:14:00 | 9 |