开发者

Query datetime in SQL without time

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'

MYSQL Date Time ref


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜