Get today's date in SQL Query

zintech
zintech used Ask the Experts™
on
I am running a query, and I would like to be able to compare today's date with a field in the database table.  As in

SELECT * FROM table1
WHERE datecolumn <= (SQL query for today's date)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
   DATE() returns the date without time
    NOW() returns the current date & time (note we've used the DATE() function in this query to remove the time)
You can do this:

select * from table1 where datecolumn <= getdate()
Is this MySQL or SQL Server? You have it in both zones.

Commented:
select * from table1 where datecolumn <= DATE(NOW());
James MurrellProduct Specialist

Commented:
SELECT * FROM table1
WHERE datecolumn <= getdate()
To compare the date without the time component:

SELECT * FROM table1
WHERE datecolumn <= convert(int,getdate())

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial