加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 获取明天的日期

发布时间:2020-12-12 16:09:28 所属栏目:MsSql教程 来源:网络整理
导读:我试图让明天的日期在一个sql语句进行日期比较,但它不工作. 以下是我的代码: select * from tblcalendarentrieswhere convert(varchar,tblcalendarentries.[Start Time],101) = convert(varchar,GETDATE() +1,101) 解决方法 要获得明天的日期,您可以使用: S
我试图让明天的日期在一个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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读