DateDiff calculation not displaying in text box

Lan Solo

Newcomer
Joined
May 28, 2003
Messages
15
Location
Alameda, CA
I am having a heck of a time getting the DateDiff result (if it's even being calculated) to pull from the mlngNumberOfDays variable and display it in the text box. Any hints would be appreciated.

Code:
'Here are the variables that are applicable to the above mentioned problem 

Private mlngNumberOfDays As Long 
Private mdatStartDate As Date 
Private mdatEndDate As Date 

'Here is the event handler 

Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click 
        mlngNumberOfDays = DateDiff(DateInterval.Day, mdatStartDate, mdatEndDate)

Thanks
 
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdatetimeclasstopic.asp

Visual Basic:
Dim date1 As New System.DateTime(1996, 6, 3, 22, 15, 0)
Dim date2 As New System.DateTime(1996, 12, 6, 13, 2, 0)
Dim date3 As New System.DateTime(1996, 10, 12, 8, 42, 0)

Dim diff1 As System.TimeSpan
' diff1 gets 185 days, 14 hours, and 47 minutes.
diff1 = date2.Subtract(date1)

Dim date4 As System.DateTime
' date4 gets 4/9/1996 5:55:00 PM.
date4 = date3.Subtract(diff1)

Dim diff2 As System.TimeSpan
' diff2 gets 55 days 4 hours and 20 minutes.
diff2 = System.DateTime.op_Subtraction(date2, date3)

Dim date5 As System.DateTime
' date5 gets 4/9/1996 5:55:00 PM.
date5 = System.DateTime.op_Subtraction(date1, diff2)

If I'm not mistaken, you can also do;
Dim numOfDays As Integer = date1 - date2
 
OK I changed the variable and the corresponding event handler to:

Code:
Private mintNumberOfDays As Integer

Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        NumberOfDays.Text = DateDiff(DateInterval.Day, mdatStartDate, mdatEndDate)

and the autos windows is giving me these messages:

mdatEndDate #12:00:00 AM# Date
mdatStartDate #12:00:00 AM# Date
mlngNumberOfDays 0 Long
radStandard Nothing System.Windows.Forms.RadioButton
 
Visual Basic:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim strStart As String = "11/06/2003 09:10:45"
        Dim strCurrent As Date
        Dim mintNumberOfDays As Integer = DateDiff(DateInterval.Day, Convert.ToDateTime(strStart), strCurrent.Now)
        MessageBox.Show("the date difference is : " & mintNumberOfDays)
    End Sub
 
Back
Top