Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 


'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

Posted

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasstopic.asp

 

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

Gamer extraordinaire. Programmer wannabe.
Posted

OK I changed the variable and the corresponding event handler to:

 


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

  • Leaders
Posted
   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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...