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