Richard Doe Richard Doe - 7 months ago 8
SQL Question

How to select SQL Server data based on today's date and time?

I'm using SQL Server to

COUNT
some data which originates from a HTML table. I want to
COUNT
total rows in the database based on today's date. And then after the date hits tomorrow's date, to set the
COUNT
value back to zero and to restart the count back from the start.

Is there a query that can help me fetch data based on current date and time?

Something like this:

SELECT COUNT(data_id)
FROM table1
WHERE clock_time BETWEEN 000000 AND 235959
AND date_time IS TODAY's DATE (or something like that)
GROUP BY XXX
ORDER BY XXX


After the clock hits tomorrow's date, I want to reset the
COUNT
back to zero, and to start a new count back from 00:00:00.

I know there is
NOW()
query but as far as I know it only shows the date.

Someone told me I could use
WHERE DATE(date)=CURDATE()
but the SQL Server won't work with that.

Thank you...

Answer

You can use convert function like this

where convert(Date,date_time)= CONVERT(Date,GETDATE())