Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Please tell me to find the diff. between two calender.

there are two calender

when we have to selected date property of two calender at the click event

then the result diff. b/w two date in integer

Please help me
Posted
Comments
Sergey Alexandrovich Kryukov 4-Nov-11 19:46pm    
There is no "int difference". What difference you need? Integer seconds or fractional seconds? Hours, milliseconds?
--SA

Solition 1 is right.

The subtract method will work.

On top of it you might want to convert the date in UTC time first especially if you're likely to have different timezone.

TimeZone is C# was quite poor but with C# 4.0 you have a more powerful TimeZoneInfo class.

The conversions methods are static members of the TimeZoneInfo class.
 
Share this answer
 
Subtraction of one time from another will give System.TimeSpan, but don't use a function, use "-" operator, which is most readable, leaves no questions:

C#
System.DateTime t1 = //...
System.DateTime t2 = //...
System.TimeSpan period = t2 - t1; // t1 - t2 is also valid, one of those results is negative.

//now what do you need?
int wholeDays = period.Days;
float days = period.TotalDays;
int wholeHours = period.Hours;
float hours = period.TotalHours;
//minutes, seconds...
int wholeMilliseconds = period.Milliseconds;
float milliseconds = period.TotalMilliseconds;


See http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^], http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA
 
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