Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to subtract two datetimepicker time value and display in 3rd datetimepicker.
reply as soon as possible.
Thank you
Wendelius 18-Aug-15 0:17am    
If you subtract two dates, you get a time interval. How would that be shown in a date time picker?
Mekalamani 18-Aug-15 0:35am    
the time interval also in time format also know, so only i ask or otherwise in textbox also no problem

Taken that you use forms, you can use the Subtract[^] method of the DateTime[^]. Consider the following code
IntervalTextBox.Text = dateTimePicker_End.Value.Subtract(dateTimePicker_Start).ToString()

Note that the return value of DateTimePicker.Value Property[^] is a DateTime.
Share this answer
Hello ,
DateTime.Subtract() method returns you the different of time between two dates .
DateTime first = new DateTime(2015, 08, 18,04,10,21);
DateTime second = System.DateTime.Now;
TimeSpan span = second.Subtract(first);	
Console.WriteLine("{0}  Minutes", span.TotalMinutes);
Console.WriteLine("{0} Hr. ", span.TotalHours);

& OP is
32.214562365  Minutes
0.53690937275  Hr.

Here I used one TimeSpan Class which is used to represent a length of time. For more information Refer : TimeSpan
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