I am comparing dates and times but it doesn't work properly sometimes
Code:
Select nit_no, workno, convert(datetime,convert(varchar,w.ExpiryDate,106) + ' ' + w.ExpiryTime), getdate()
from works w
where NIT_No= 3594 and WorkNo=1
and convert(datetime,convert(varchar,w.ExpiryDate,106) + ' ' + w.ExpiryTime) <= getdate()
Values:
convert(datetime,convert(varchar,w.ExpiryDate,106) + ' ' + w.ExpiryTime)= 2017-06-08 16:50:54.000
getdate()= 2017-06-08 17:50:54.000
ExpiryDate is of DATE type and ExpiryTime is of type VARCHAR
It doesn't work properly, getdate() is less than another expression and stills returns the data.
Update: What I am trying to do is comparing ExpiryDate and ExpiryTime with current Datetime i.e. Getadate(), if expiry date and time is less than current datetime then it shouldn't be displayed else displayed.