Newbie Question - Date Difference

  • Thread starter Thread starter John Espinosa
  • Start date Start date
J

John Espinosa

I am in need to figure out of dateA - dateB = aNumber
Is there a method in the .Net Framework that will do this for me?
I have changed the dates in a text box to the date type using CDate method

I appreciate the help.

John
 
Hi John,

considering that you got two text boxes on the form and one button.

1textbox name = textbox1
2textbox name = textbox2
button name = button1

so when user clicks on the button1 u want to perform the date calculation,
it can be done in the following manner by using CDate:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CDate(TextBox1.Text).Subtract(CDate(TextBox2.Text))
End Sub

Hope this helps..
 
* "John Espinosa said:
I am in need to figure out of dateA - dateB = aNumber
Is there a method in the .Net Framework that will do this for me?
I have changed the dates in a text box to the date type using CDate method

'DateDiff' or the date's 'Subtract' method.
 
Hi John,

In addition to Dhaval and Herfried,

There is a special class for date difference.

The TimeSpan

I think that Dhaval forgot to write that part in his sample.

Dim mytimespan as Timespan =
CDate(TextBox1.Text).Subtract(CDate(TextBox2.Text))

I hope this helps,

Cor
 
well, timespan can be used.. but if dont want to use then it can be done by
this..

MsgBox (CDate(TextBox1.Text).Subtract(CDate(TextBox2.Text)).TotalDays)

but thanks for letting me know.. coz of this I found a small error that of
..TotalDays part.. as the date gets in prompt so got to convert it in string
or integer and TotalDays gives it.
 
Back
Top