GPSPOW
asked on
Comparing string dates in SQL
I have a SQL query which outputs dates as a Char field so I can have blank date fields as '' instead of 1900-01-01.
I am trying to write the query so only records with anExpiresDate > getdate() - 19:
ExpiresDate
>convert(char,GETDATE()-19 ,101)
However, when the the query runs, I get data for prior years witin the Month and Day period, but for prior years.
What is the syntax to only get data > 7/1/2015 and not anything for July of 2014.
ExpiresDate is stored as Varchar (30).
Thanks
Glen
I am trying to write the query so only records with anExpiresDate > getdate() - 19:
ExpiresDate
>convert(char,GETDATE()-19
However, when the the query runs, I get data for prior years witin the Month and Day period, but for prior years.
What is the syntax to only get data > 7/1/2015 and not anything for July of 2014.
ExpiresDate is stored as Varchar (30).
Thanks
Glen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'd recommend this: DATE and TIME ... don't be scared, and do it right (the first time)
It isn't good practice to store date/time information as strings, even more so if you have used MM/DD/YYYY as the storage format.
It isn't good practice to store date/time information as strings, even more so if you have used MM/DD/YYYY as the storage format.
ASKER
Glen