Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
DateTime dt1 = Calendar2.SelectedDate;
DateTime dt2 = Calendar1.SelectedDate;
TimeSpan ts = dt1 - dt2;
int days = ts.Days;
txtDays.Text = ts.ToString();
Posted 23-Feb-13 22:26pm
Edited 23-Feb-13 22:47pm
v3
Comments
OriginalGriff at 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 at 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 at 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 at 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
good
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!
 
http://msdn.microsoft.com/en-gb/library/dd992632.aspx[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 160
2 jlopez788 109
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,589
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
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