Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 24, 2013 10:38 AM by Clubict
Jan 24, 2013 10:02 AM|LINK
I've a question with date compaire in sql.
In my believes < is smaller and > is bigger
But when i run the statement below it doesn`t return true..
Correct me if I'm wrong, but isn`t the date of today bigger than the date of last year?
Jan 24, 2013 10:07 AM|LINK
You are converting to varchar so are comparing the strings alphabetically rather than treating them as dates
where CONVERT(datetime,GETDATE(),101) > CONVERT(datetime,'12/31/2012',101)
Jan 24, 2013 10:11 AM|LINK
Select 'true'where GETDATE() > '12/31/2012'
Jan 24, 2013 10:13 AM|LINK
Why are you converting to a string instead of comparing dates?
This returns true:
Select 'true' where GetDate() > '12/31/2012'
Jan 24, 2013 10:28 AM|LINK
-- Compare year
DATEPART(yyyy, GETDATE()) = 2012
-- compare month
AND DATEPART(mm, GETDATE()) = 31
-- compare day
AND DATEPART(dd, GETDATE()) = 12
Jan 24, 2013 10:38 AM|LINK
So what ypu are saying is that i need to convert it back to date?
It has done the trick!..Thanks!