选择两个日期之间的所有记录的简单方法
有没有一种简单的方法来选择两个日期之间的所有记录。我应该使用 datetime
作为归档类型,还是也可以使用字符串类型。像这样的事情:
SELECT * FROM users WHERE datetime_update is between date1 and date2
- 由于某些原因我使用字符串字段类型,这样会更好。
我在我的 c# 项目中尝试这个命令,但它返回了注释。我哪里缺少理解?
SELECT user_id, sharj_value, datetime_update
FROM users
WHERE (user_id = 0653193963) AND (datetime BETWEEN '1390/07/12%' AND '1390/07/14%')
这是表中的数据示例,
filed names user_id sharj_value datetime_update
0653193963 60000 1390/7/12 08:00:15
0653193963 40000 1390/7/13 08:18:44
0653193963 40000 1390/7/13 08:20:35
我认为它应该返回最后两行。
are there a simple way to select all record that are between two date. should i use datetime
for filed type or i can use string type too. something like this :
SELECT * FROM users WHERE datetime_update is between date1 and date2
- i use string filed type for some reasons so that would be better.
i try this command in my c# project but it return noting. where am i miss understanding ?
SELECT user_id, sharj_value, datetime_update
FROM users
WHERE (user_id = 0653193963) AND (datetime BETWEEN '1390/07/12%' AND '1390/07/14%')
and this is sample of data in table
filed names user_id sharj_value datetime_update
0653193963 60000 1390/7/12 08:00:15
0653193963 40000 1390/7/13 08:18:44
0653193963 40000 1390/7/13 08:20:35
it suppose to return two last row i think.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个..
Try this..
对于 SQL Server,此 T-SQL 语法应该有效:
另请注意,某些语言环境具有年-月-日(例如美国),而其他语言环境则使用年-日-月。
您可能还想查看 SQL-Server 的“设置日期格式”
For SQL Server, this T-SQL syntax should work:
Note, too, that some locales have year-month-day (like America), and others use year-day-month.
You might also want to look at SQL-Server's "set dateformat"