Reputation: 11423
How to check two times if they are in the same date or not ?
For example
first- 08:00:00
second- 16:00:00
in the same date .
first- 20:00:00
second- 04:00:00
two different dates
Upvotes: 0
Views: 223
Reputation: 1
Are you saying that if the time of the first value is higher than the time of the second value it is a different date?
If so you can simply use less than or greater than:
declare @t1 time = '08:00:00'
declare @t2 time = '16:00:00'
declare @t3 time = '20:00:00'
declare @t4 time = '04:00:00'
if (@t1 < @t2)
PRINT 'same day'
if (@t3 > @t4 )
print 'different day'
Upvotes: 0
Reputation: 40491
You can use CASE EXPRESSION
:
SELECT CASE WHEN t.first > t.second THEN 'Two different dates'
ELSE 'In the same date'
END as your_ind
FROM YourTable
Upvotes: 1