Zhen Chua
Zhen Chua

Reputation: 5

days gap between 2 dates

i am facing problem when i'm getting difference between 2 dates. For example, '9/11/2016' minus '7/11/2016' the result comes out 62. Why? Anyone can help me please? Any response is appreciated, Thanks in advance. :)

Protected Sub txtReturnDate_TextChanged(sender As Object, e As EventArgs) Handles txtReturnDate.TextChanged

    Dim d1 As DateTime = txtArriveDate.Text
    Dim d2 As DateTime = txtReturnDate.Text

    Dim days As Integer = (d2 - d1).TotalDays
    lblDuration.Text = days.ToString()
End Sub

Upvotes: 0

Views: 101

Answers (1)

Mukul Varshney
Mukul Varshney

Reputation: 3141

62 = days between 11 july 2016 and 11 sep 2016. Try below for date conversion. This will avoid the confusion of day vs month.

Dim dt As DateTime = DateTime.ParseExact(txtArriveDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture)

Upvotes: 1

Related Questions