solve date difference function?

avi4ever

Member
Joined
Feb 27, 2009
Messages
7
Programming Experience
1-3
I am taken DateTimePicker2, DateTimePicker3 n textbox6.

Nw i wanted to display the result of subtraction of these two dates(DateTimePicker2-DateTimePicker3) in textbox6 automatically. I don't want to enter the result manually. Plz hlp me I need it badly. I hav already tried in lost focus event also its nt workin. Plz hlp me
 
VB.NET:
    TextBox6.Text = CType(DateTimePicker2.Value-DateTimePicker3.Value,TimeSpan).ToString

I'm not sure on the correct property of the DateTimePicker but I imagine Value is it.
 
Have a look at the DTP class in help, ValueChanged event should catch your immediate attention, especially if you rule out the inherited events. Use the ValueChanged event.
 
Solve da problem of Date diff function

:confused: how to do a subtraction between two dates (4/21/2009 - 5/26/2009). It should display in da textbox1.text(month=1) n textbox2.text(Days=5) . How to do dat? Sumone plz hlp me
 
Well, we told you to look at the TimeSpan object. When you subtract two dates it gives you a TimeSpan object.

Meaning:
VB.NET:
DateTimePicker2.Value-DateTimePicker3.Value

will give you a TimeSpan Object. So you can then take that object and use its properties and dispay the appropriate data.

VB.NET:
dim difference as TimeSpan = DateTimePicker2.Value-DateTimePicker3.Value
difference.Days
difference.Hours
difference.Minutes
difference.Seconds
difference.Ticks
 
DateDiff(DateInterval.Day, DateTimePicker2.Value, DateTimePicker3.Value)

Difference, in this case in days, between the two.
 
Back
Top