开发者

Datediff() function not getting the expected result in VB.NET

I am using the following code in my project. I want to find the number of days by given the last date and now.开发者_JAVA技巧

Dim BorrowDate As Date
Dim i As Integer
BorrowDate = Date.Parse(txtBorrowDate.Text)
i = DateDiff(DateInterval.Day, BorrowDate, DateTime.Now)

for example, when BorrowDate is "01/Jul/2011" then the result is 7 days which it should be 10 to now. Please help


Since you are using .Net you might try this

    Dim BorrowDate As Date = Date.Parse(txtBorrowDate.Text)

    Debug.WriteLine(BorrowDate.ToString)
    Debug.WriteLine(DateTime.Now.ToString)

    Dim ts As TimeSpan = DateTime.Now - BorrowDate

    Dim numdays As Integer = CInt(ts.TotalDays)

    Debug.WriteLine(numdays.ToString("n0"))

edit: Init the variables and show the dates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜