Click here to Skip to main content
15,907,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
System.DateTime f = dateTimePicker1.Value;
System.DateTime g = dateTimePicker2.Value;
System.TimeSpan diff = f.Subtract(g);
textBox1.Text = Convert.ToString(diff);




I can't get the date difference.

When I select 12/05/2013 and 25/06/2013, I get the difference as 00.00.0000.


How can I find the date difference?
Posted
Updated 22-May-13 2:20am
v3
Comments
Mahesh Bailwal 22-May-13 8:16am    
Both f and g contains same value so difference is zero.

You're subtracting g from f. That's fine. But beforehand, you assign dateTimePicker1.Value to both variables.

You should assign another DateTimePicker's Value to one of the variables g or f.
 
Share this answer
 
try this
C#
System.DateTime todt = dateTimePickerTodate.Value;
System.DateTime fromdt = dateTimePickerFromdate.Value;
System.TimeSpan diff = todt.Subtract(fromdt);//generally we substract smallar date from bigger else it will return Totaldays in negative sign
textBox1.Text = Convert.ToString(diff.TotalDays);

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900