我试图让明天的日期在一个sql语句进行日期比较,但它不工作.
以下是我的代码:
select * from tblcalendarentries where convert(varchar,tblcalendarentries.[Start Time],101) = convert(varchar,GETDATE() +1,101)
解决方法
要获得明天的日期,您可以使用:
SELECT DATEADD(day,1,GETDATE())
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.