All Forums General
Zbark 2 posts Joined 05/15
06 May 2015
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?

dnoeth 4628 posts Joined 11/04
06 May 2015

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

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

 

Dieter

Zbark 2 posts Joined 05/15
07 May 2015

Brilliant! It worked right away. Thanks so much. 

You must sign in to leave a comment.