Reputation: 79
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...
Upvotes: 0
Views: 8631
Reputation: 1587
Need not to use time as you want today's data.
Try this one
SELECT COUNT(data_id) FROM table1
WHERE convert(date,date_time) = getdate()
Upvotes: 1
Reputation: 4844
You can use convert function like this
where convert(Date,date_time)= CONVERT(Date,GETDATE())
Upvotes: 3