开发者

Query datetime in SQL without time

开发者 https://www.devze.com 2023-02-15 11:45 出处:网络
I开发者_开发知识库\'m trying to write a SQL query which should just pick the count with specific date not 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

精彩评论

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