-2

In T-SQL is there a way to filter by greater than a date given in dd/mm/yyyy format?

so for example:

SELECT BIRTHDAY FROM ATABLE WHERE BIRTHDAY > 12/12/1990
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2405469
  • 1,953
  • 2
  • 22
  • 43
  • Possible duplicate of this question, http://stackoverflow.com/questions/10643379/how-do-i-query-for-all-dates-greater-than-a-certain-date-in-sql-server – Geoff Dawdy Mar 26 '14 at 16:21
  • 12/12/1990 would yield 0, due to integer math. – swasheck Mar 26 '14 at 16:45
  • So I've got to ask why do you care what the date format is for a `WHERE` clause? 1/1/1991 is greater than 12/12/1990 no matter how you format it... – Zane Mar 26 '14 at 16:48
  • This is difficult to know how to answer without knowing the collation settings, the data type in the table, and your regional settings as well. Can you please post this information? – swasheck Mar 26 '14 at 16:50

1 Answers1

6

Since many date formats are dependent on language & regional settings, I recommend to always use the ISO-8601 format of YYYYMMDD - and of course, also put your date literal into single quotes:

SELECT Birthday
FROM dbo.ATable 
WHERE Birtday > '19901212'

This works on all SQL Servers - regardless of what language, date and regional settings you have

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459