-1

I am trying to pass 2 variables check in date and check out date from 2 different date time picker on a form. The goal is two calculate the number of day between the 2 dates.

Here is what I have so far:

From the form:

Public Class FormReservations

'Declare the new objects:

Private TheRegularPriceObject As ClassRegularPrice


Private Sub ButtonCalculateRate_Click(sender As Object, e As EventArgs) Handles ButtonCalculateRate.Click

TheRegularPriceObject = New ClassRegularPrice(DateTimePickerCheckIn.Value.Date.ToString("dd/MM/yyyy"),DateTimePickerCheckOut.Value.Date.ToString("dd/MM/yyyy"))




        LabelNumberOfDay.Text = TheRegularPriceObject.CalculateNumberOfDay.ToString()
    End If


End Sub

End Class

This is from the class

 Public Class ClassRegularPrice



Protected CheckInDateVar As String

Protected CheckOutDateVar As String
Protected NumberOfDaySpan As Integer

'Constructor: 

Public Sub New(ByVal CheckInDateConst As String, ByVal CheckOutDateConst As String)

CheckInDate = CheckInDateConst
CheckOutDate = CheckOutDateConst
CalculateNumberOfDay()
End Sub

Property CheckInDate() As Date
    Get
        Return CheckInDateVar
    End Get
    Set(ByVal Value As Date)
        CheckInDateVar = Value
    End Set
End Property


Property CheckOutDate() As Date
    Get
        Return CheckOutDateVar
    End Get
    Set(ByVal Value As Date)
        CheckOutDateVar = Value
    End Set
End Property
Sub 


 'Methods:
Sub CalculateNumberOfDay()

    NumberOfDaySpan = (CheckOutDateVar - CheckInDateVar)
End Sub

It is not returning a value and I'm not sure I converted my date to string also, but this is what I have been told to do. I am not sure from there how the calculation should work since this is a string... Any help would be greatly appreciated.:)

Sascha
  • 1,210
  • 1
  • 17
  • 33

1 Answers1

0
Dim elapsedTime As TimeSpan

first = reader.GetDateTime("first datimepicker")
second = reader.GetDateTime("second datimepicker")

elapsedTime = second.Subtract(first)
Pedram
  • 6,256
  • 10
  • 65
  • 87
Mike Araya
  • 155
  • 1
  • 11
  • you didn't tell where you are storing the values of each datetime picker but if you are retrieving it from database this should work. by using datareader – Mike Araya Jan 07 '16 at 20:40
  • Hello again, The two dates picked from the 2 different datetimepickers are not being stored. They are simply being chosen from the form. By clicking the calculate button, this is where the number of days between the two dates is calculated. When you are declaring the variables and making the calculation, are ypu in the class or in the form? sorry... Dim elapsedTime As TimeSpan first = reader.GetDateTime("first datimepicker") second = reader.GetDateTime("second datimepicker") elapsedTime = second.Subtract(first) – Marie Vallieres Jan 07 '16 at 20:56