微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql – 获取明天的日期

我试图让明天的日期在一个sql语句进行日期比较,但它不工作.

以下是我的代码

select * 
from tblcalendarentries
where convert(varchar,tblcalendarentries.[Start Time],101) 
      = convert(varchar,GETDATE() +1,101)

解决方法

要获得明天的日期,您可以使用:
SELECT DATEADD(day,1,GETDATE())

所以在where子句中添加到你的代码中:

where convert(varchar,101) = 
      convert(varchar,DATEADD(day,GETDATE()),101)

首先,GETDATE()将以以下格式获取今天的日期:

2013-04-16 10:10:02.047

07000

Returns the current database system timestamp as a datetime value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of sql Server is running.

然后使用DATEADD(),允许您从指定的日期添加(或减少必要的)日期或时间间隔.所以间隔可以是:年,月,日,小时,分钟等

07001

Returns a specified date with the specified number interval (signed integer) added to a specified datepart of that date.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐