我需要帮助,我希望获得2个日期之间的日子,不包括星期五,如果第一个日期计算2天,除了周五做某事 例如:date1 = 17/10/2016 date2 = date.now 我想向date1添加2天并检查date1< date2然后做点什么
更多enplane:如果有应用程序添加发票,则每个添加的发票都有日期 并且每天进行代码检查并获取今天的日期,每天检查发票日期是否有2天,除了星期五未计算的事情。
我想到它可以获得Date1.day + 2的日期并将其与今天的date.day进行比较
GetDayOfDate = Date1.day + 2
TodayDate = Date.Now.Day
if GetDayOfDate < TodayDate then
do somthing
End If
但是这段代码并不完整,因为我不想计算星期五,而且如果今天的日期是下个月的第一天那么条件将不适用,因为今天的日期是&lt; GetDayOfDate
任何想法如何编码?!
希望你明白我的意思:D
答案 0 :(得分:0)
伙计们,我发现了这个问题并在这里进行测试,如果有人需要的话
Dim GetDate As Date
GetDate = 'put the date you want to increment it 2 business days
Dim numDays As Integer
numDays = 2
Dim totalDays As Integer
Dim businessDays As Integer
Dim currDate As DateTime
totalDays = 0
businessDays = 0
While businessDays < numDays
totalDays += 1
currDate = GetDate.AddDays(totalDays)
If Not (currDate.DayOfWeek = DayOfWeek.Friday) Then
businessDays += 1
End If
End While
'to check if the date after increment the 2 work days are less than the day of now
If currDate < Date.Now Then
'date is expired
else
'date is not expired yet
End If