Click here to Skip to main content
13,348,874 members (76,212 online)
Rate this:
Please Sign up or sign in to vote.
See more:
DateTime dt1 = Calendar2.SelectedDate;
DateTime dt2 = Calendar1.SelectedDate;
TimeSpan ts = dt1 - dt2;
int days = ts.Days;
txtDays.Text = ts.ToString();
Posted 23-Feb-13 23:26pm
Updated 23-Feb-13 23:47pm
OriginalGriff 24-Feb-13 4:30am
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Sandeep Mewara 24-Feb-13 4:40am
|This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Gilbertinino 24-Feb-13 4:46am
My question is how can I deduct two dates and I get a result like '4' not '4.00:00:00'
Sandeep Mewara 24-Feb-13 4:48am
And what if the difference is 0.00:04:53?

You have to share what exactly you are tring to do and whats the end goal expected. difference between two dates will vary from seconds to years. What are you looking for?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ah! That makes more sense.

Don't use the default TimeSpan.ToString: it returns a timespan as days.hours:minutes:seconds
Instead, use a format string to return only the bit you are interested in:
txtDays.Text = ts.ToString("d");
Or use the days value you have already extracted![^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100