0
我需要找到两个日期之间的差异并加上一些限制。两个日期之间的星期/月的差异
- 如果在几个月的差大于6,然后显示在个月的差
- 如果小于6个月,在周
- 显示它最后,总是向上舍入到下一个整数(6.2周---> 7)
我已经试过这
Dim startDate As Date = txtStartDate.DateValue
Dim endDate As Date = txtEndDate.DateValue
Dim dateDiff As TimeSpan = endDate - startDate
Dim totalDays As Double = dateDiff.TotalDays
'Divide by 7 to get the number of weeks
Dim weeks As Double = totalDays/7
'6 months, average of 4.34812 weeks per month
If (weeks >= 26.08872) Then
txtDuration.Text = Math.Ceiling((weeks/4.34812)).ToString() + " Months"
Else
txtDuration.Text = Math.Ceiling(weeks).ToString() + " Weeks"
End If
它适用于一些日期,但并不适用于所有情况。
- 2014年9月1日 - > 2015年3月1日给我26周,要6个月
任何想法?有没有在vb.net中的内置函数,我可以使它更容易?
感谢
有这些日期间181天,它是25.857142857周 – 2014-09-25 20:32:56