如何使用带有日期条件的选择? [英] How do I use select with date condition?
问题描述
在 sqlserver 中,如何比较日期?例如:
In sqlserver, how do I compare dates? For example:
从注册日期 >= '1/20/2009' 的用户中选择 *
Select * from Users where RegistrationDate >= '1/20/2009'
(RegistrationDate 是日期时间类型)
(RegistrationDate is datetime type)
谢谢
推荐答案
如果你把
SELECT * FROM Users WHERE RegistrationDate >= '1/20/2009'
它会自动将字符串 '1/20/2009'
转换为 DateTime
格式,用于日期 1/20/2009 00:00:00
.因此,通过使用 >=
,您应该获取注册日期为 2009 年 1 月 20 日或更晚的每个用户.
it will automatically convert the string '1/20/2009'
into the DateTime
format for a date of 1/20/2009 00:00:00
. So by using >=
you should get every user whose registration date is 1/20/2009 or more recent.
我把它放在评论部分,但我也应该把它链接到这里.这是一篇文章,详细介绍了在查询中使用 DateTime 的一些更深入的方法:http://www.databasejournal.com/features/mssql/article.php/2209321/Working-with-SQL-Server-DateTime-Variables-Part-Three---Searching-for-Particular-Date-Values-and-Ranges.htm
I put this in the comment section but I should probably link it here as well. This is an article detailing some more in depth ways of working with DateTime's in you queries: http://www.databasejournal.com/features/mssql/article.php/2209321/Working-with-SQL-Server-DateTime-Variables-Part-Three---Searching-for-Particular-Date-Values-and-Ranges.htm
这篇关于如何使用带有日期条件的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!