hello my friends ... in C# Forms ( application form)
my question is about the (DateTimePicker)
is there any way to calculate the days between two different times which were entered by the tool DateTimePicker by an existing method or something else ...
thank you in advance

Recommended Answers

All 3 Replies

Using 2 datetime pickers you can get the timespan between them

TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value;
            MessageBox.Show(ts.ToString());

To do what you're suggesting would probably take the user putting in one of them to the DTP, hitting a button to lock the value into one DateTime object, choosing a new date then hitting the button again (or something to that effect).
Either way the timespan is the way to measure the difference and then you can take the timespan apart based on seconds, minutes, total seconds, etc.

Thank you so much
as it's givin me the days with some parts of the time
I will let the program save the the numbers before the first Dot in a variable .. and these numbers will represent the days
thank you so much

Or you can access that directly from ts.Days in the above code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.