squonk
squonk

Reputation: 3

SQL Query: finding the 'day' value from a SQL DateTime

I have a table with the fields timeout and timein. I need to return a list of records where timeout is on a different day to timein. How can I achieve this?

Upvotes: 0

Views: 208

Answers (3)

StevieG
StevieG

Reputation: 8709

If both dates are in the same month, then:

select * 
from table 
where DAY(timeout) <> DAY(timein0) 

or

select * 
from table 
where DATEPART(day,timeout) <> DATAPART(day,timein) or

will work..

If, however, they can be in different months, then you need to compare the full dates. This should do that for you:

select *
from table
where DATEDIFF(day,timeout,timein) <> 0

Upvotes: 3

Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36591

How about this :

select *
from table
where day(timeout) != day(timein);

Upvotes: 0

Gopal Sanodiya
Gopal Sanodiya

Reputation: 204

select * 
from table_name 
where datediff(dd,timein,timeout) > 0 (for day in greater then today)

if want next day time out then

select * 
from table_name 
where datediff(dd,timein,timeout) =1

Upvotes: 1

Related Questions