Link to home
Start Free TrialLog in
Avatar of GPSPOW
GPSPOWFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of TONY TAYLOR
TONY TAYLOR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPSPOW

ASKER

Thanks

Glen
Avatar of PortletPaul
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.