SQL Query: finding the 'day' value from a SQL DateTime
I have a tab开发者_Python百科le 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?
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
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
How about this :
select *
from table
where day(timeout) != day(timein);
精彩评论