Brian McGarvie | Find out more information on Brian M McGarvie and his IT consultancy, and personal adventures and experiences…

Aug/07

23

SQL – Select using current day…

I’ve had this problem a few times, and many people always ask me it… so here it is immortalised.

If you require to select all records added to your table for the current day use the following where clause – obviously ‘col’ should be the name of your datetime column…

Hope this helps you all as much as it has myself!
select *
from mytable
where datediff(day,getdate(),col)=0 and col <= getdate()

Bookmark and Share

RSS Feed

No comments yet.

Leave a comment!

«

»

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Find it!

Tags