I'm trying to write a SQL query which should just pick the count with specific date not time.
select count(*) from xyz where time='2010-01-21'
but it is not returning any results.
For SQL Server 2008, you should be able to use the date data type:
select count(*) from xyz where cast(time as date) = '2010-01-21'
If you have a date time field, and you wanted to match a date:
select count(*) from xyz where time BETWEEN '2010-01-21' AND '2010-01-22
'
Try (MySQL)
SELECT COUNT(*) FROM xyz WHERE DATE(datetime_col) = '2010-01-21'
in T-SQL (MSSQL) (kinda ugly, but should work):
SELECT * FROM xyz WHERE CAST(CONVERT(varchar(8), datetime_col, 112) AS DATETIME) <= '2011-01-21'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With