本文介绍了如何在日期之前进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我通过
When i pass
@Reminderdays int=7,
@DayOfReminder int=1,
@MonthOfReminder int=8
他们应该在7天之后给我,即2015年8月7日,
但由于某种原因,它给予了我9-8-2015 ..我不明白如何计算日期,这给了我额外的提前日期
they should give me after 7 days date i.e 7-08-2015 ,
but for some reason it is giving me 9-8-2015 .. I don't understand how the date is getting calculated which is giving me extra ahead date
Declare @company_id int =159,
@IsSendEmailToEmployee bit = 1,
@IsSendEmailToHR bit =0,
@IsSendEmailToManagersManager bit =0,
@IsSendEmailToManager bit=1,
@Reminderdays int=7,
@DayOfReminder int=1,
@MonthOfReminder int=8,
@CompanyYear datetime='2015-04-01'
set @CompanyYear = Convert(datetime,'1 Jan ' + Cast(Year(@CompanyYear) as varchar),101)
Select Convert(datetime,Convert(varchar(10) ,
DATEADD(dd,+@Reminderdays,DATEADD(dd,@DayOfReminder,DATEADD(Month,@MonthOfReminder-1,@CompanyYear))),101)) as after
推荐答案
DECLARE @Reminderdays int=7,
DECLARE @DayOfReminder int=1,
DECLARE @MonthOfReminder int=8
SELECT DATEADD(DAY, @DayOfReminder, DATEFROMPARTS(YEAR(GETDATE()), @MonthOfReminder, @DayOfReminder)) AS DayAfterBefore
这篇关于如何在日期之前进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!