2014-09-27 122 views
1
Dim intYear, intMonth, intDay As Integer, strResult As String, tspResult As TimeSpan 


     intYear = Integer.Parse(txtYear.Text) 
     intMonth = Integer.Parse(txtMonth.Text) 
     intDay = Integer.Parse(txtDay.Text) 

Dim dteDatum As New System.DateTime(intYear, intMonth, intDay) 

      tspResult = Now.Subtract(dteDate) 
     strResult = Math.Abs(tspResult.Days).ToString 
      MessageBox.Show(strResult) 

例如: 今天是10月1日,我想知道到10月4日爲止有多少天。 該程序會說2天,但這是錯誤的,它必須是3天。 我該如何解決這個問題? (以前的計算結果很好) 非常感謝,如果我的英語很糟糕,我很抱歉。計算天數到特定日期

回答

2

Try use datediff

' The following statements set datTim1 to a Thursday 
' and datTim2 to the following Tuesday. 
Dim datTim1 As Date = #1/4/2001# 
Dim datTim2 As Date = #1/9/2001# 
' Assume Sunday is specified as first day of the week. 
Dim wD As Long = DateDiff(DateInterval.Weekday, datTim1, datTim2) 
Dim wY As Long = DateDiff(DateInterval.WeekOfYear, datTim1, datTim2)