选择两个日期之间的所有记录的简单方法

发布于 2024-12-08 13:38:44 字数 776 浏览 0 评论 0原文

有没有一种简单的方法来选择两个日期之间的所有记录。我应该使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法唧唧 2024-12-15 13:38:44

试试这个..

SELECT user_id, sharj_value, datetime
  FROM users
 WHERE user_id = 0653193963 AND datetime BETWEEN '1390/07/12 00:00:00' AND '1390/07/14 23:59:59')

Try this..

SELECT user_id, sharj_value, datetime
  FROM users
 WHERE user_id = 0653193963 AND datetime BETWEEN '1390/07/12 00:00:00' AND '1390/07/14 23:59:59')
紙鸢 2024-12-15 13:38:44

对于 SQL Server,此 T-SQL 语法应该有效:

SELECT user_id, sharj_value, [datetime]
FROM users
WHERE user_id = 06531939630 AND [datetime] BETWEEN '1390-07-12' AND '1390-07-14'

另请注意,某些语言环境具有年-月-日(例如美国),而其他语言环境则使用年-日-月。

您可能还想查看 SQL-Server 的“设置日期格式

For SQL Server, this T-SQL syntax should work:

SELECT user_id, sharj_value, [datetime]
FROM users
WHERE user_id = 06531939630 AND [datetime] BETWEEN '1390-07-12' AND '1390-07-14'

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文