Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hii friends...

How to calculate total days diffrence between two dates..??

Thanks in advance.
Posted

Lets assume you have Date1 and Date2 which are both DateTime type and you wish to calculate the difference between them in entire days.

You calculate the difference between the two dates, using the TimeSpan class.
C++
TimeSpan diff = myDate2.Subtract(myDate1);  


Then you convert the result ("diff") to whole days.
C++
double DaysDiff = diff.TotalDays;  
 
Share this answer
 
Comments
phil.o 8-Mar-13 5:11am    
5'd!
Michael Haephrati 8-Mar-13 5:12am    
Thanks
Maciej Los 8-Mar-13 5:19am    
Good, +5!
Nandakishore G N 8-Mar-13 8:27am    
good answer.My 5..
Avik Ghosh22 8-Mar-13 11:00am    
5!
If you want to do it in sql query, use DATEDIFF[^] function.
 
Share this answer
 
in sql
select DATEDIFF(d,'1/10/2012','1/20/2012') find days
format MM/dd/yyyy in sql
in c#
date1
date2
timespan st=date1.subtract(date2);
string totaldate=st.totaldays.tostring();
 
Share this answer
 
v2

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