Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with vb.net code for date/time 1

Status
Not open for further replies.

maac74

Technical User
Jul 27, 2005
12
0
0
US
hello all, I'm a newbie at this. But anyways, I'm trying to figure out how to get a textbox to display the number of days between dates. I got 2 date time pickers on the vb.net app named dtpstartdate and dtpenddate. Now lets say I choose the start day as today, then choose the end date 3 days from now. I need to figure out the code to get the number of days between the dates displyed in the textbox. any help would be appreciated.
 
You could try something like:

Code:
  Private Sub dtpStartDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.ValueChanged

    TextBox3.Text = DateDiff(DateInterval.Day, dtpStartDate.Value, dtpEndDate.Value).ToString

  End Sub

  Private Sub dtpEndDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.ValueChanged

    TextBox3.Text = DateDiff(DateInterval.Day, dtpStartDate.Value, dtpEndDate.Value).ToString

  End Sub

or using a single handler

Code:
  Private Sub dtpStartEndDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.ValueChanged, dtpEndDate.ValueChanged

    TextBox3.Text = DateDiff(DateInterval.Day, dtpStartDate.Value, dtpEndDate.Value).ToString

  End Sub

Hope this helps.

[vampire][bat]
 
that was just what I was looking for. Thanks that helped me out a bunh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top