我正在尝试传递2个变量检查日期,并从表单上的2个不同日期时间选择器中查看日期。目标是两个计算两个日期之间的天数。
这是我到目前为止所做的:
从表格中:
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
结束班
这是来自班级
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
它没有返回值,我也不确定我是否也将日期转换为字符串,但这是我被告知要做的事情。我不确定计算应该如何工作,因为这是一个字符串...任何帮助将不胜感激。:)
答案 0 :(得分:0)
Dim elapsedTime As TimeSpan
first = reader.GetDateTime("first datimepicker")
second = reader.GetDateTime("second datimepicker")
elapsedTime = second.Subtract(first)