Super Basic: How do you use 'Date' as a qualifier in a query?

General
Fan

Super Basic: How do you use 'Date' as a qualifier in a query?

I am trying to query based on a specific date. For example:

select name, dept, dateofhire

from table

where date of hire >= 12/31/2010

group by name, dept, dateofhire

I regularly get results that contain dates of hire before 12/31/2010.

I've even tried casting the date to match a specific format:

where cast(cast(dateofhire as format 'mm-dd-yy') as varchar(15))  >= '12-31-10'

but to no avail.

Summary: my goal is to query using a date as a parameter but cannot seem to make it work.

What am I missing here?

2 REPLIES
Junior Contributor

Re: Super Basic: How do you use 'Date' as a qualifier in a query?

There's only one recommended way to write a date using Standard SQL syntax:

where dateofhire >= DATE '2010-12-31'
Fan

Re: Super Basic: How do you use 'Date' as a qualifier in a query?

Brilliant! It worked right away. Thanks so much.