如何检索之前的日期并在查询中使用它?
我想检索前一个日期(即当前日期减 1)并通过 = 运算符在查询中使用它。
我收到以下查询来检索前一个日期:select DATEADD(DD, DATEDIFF(DY, 0, GETDATE()), -1)
它给出: 2011-03-14 00:00:00.000
我想仅获取:2011-03-14,并在查询中使用它来检查列的数据。
类似于:select * from table where column1 in ('values list') and date=(previous_date)
如何将两者结合起来并以我想要的格式获得它?
I would like to retrieve the previous date (i.e., current date minus 1) and use it in a query through an = operator.
I got the following query to retrieve the previous date:select DATEADD(DD, DATEDIFF(DY, 0, GETDATE()), -1)
It gives: 2011-03-14 00:00:00.000
I would like to get only: 2011-03-14, and use this in a query to check against a column's data.
Something like:select * from table where column1 in ('values list') and date=(previous_date)
How can I combine the two and get it in the format I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能会解决您的问题。
This might resolve your issue.
用途:
问候
Use :
Regards
我得到了我想要的东西:
感谢您的帮助!
I got what I was looking for:
Thanks for your help!