【问题标题】:Add 2 days work for Date vb.net为 Date vb.net 添加 2 天的工作
【发布时间】:2016-10-17 23:16:31
【问题描述】:

请我需要帮助,如果第一个日期算作除周五之外的 2 天,我想获取 2 个日期之间的天数,不包括周五 例如:date1 = 17/10/2016 date2 = date.now 我想在 date1 中添加 2 天并检查 date1

更多飞机:如果有申请添加发票,每张添加的发票都有日期 并且每天检查代码并获取今天的日期,每天检查发票日期是否有 2 天除了星期五没有计算做一些事情。

我想得到 Date1.day + 2 的日期并将其与今天的 date.day 进行比较

GetDayOfDate = Date1.day + 2
TodayDate = Date.Now.Day 
if GetDayOfDate < TodayDate  then
do somthing
End If

但是这段代码不完整,因为我不想计算星期五,而且如果今天是下个月的第一天,那么条件将不适用,因为今天是

任何想法如何编码?!

希望你明白我的意思:D

【问题讨论】:

标签: vb.net visual-studio date


【解决方案1】:

伙计们,我找到了解决方案并在这里测试它,如果有人需要它

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    相关资源
    最近更新 更多