Saturday, September 25, 2010

How to calculate hour difference

Example:05:00 15:00 = 10 hours07:00 12:00 = 5 hours
Code:
int y = DateTime.Now.Year, m = DateTime.Now.Month, d = DateTime.Now.Day, s = 0;
DateTime startTime = new DateTime(y, m, d, 5, 30, s); // 05:40 Hour
DateTime endTime = new DateTime(y, m, d, 17, 45, s); // 17:45 Hour
TimeSpan diff = endTime - startTime;
int hourDiff = diff.Hours; // 12 Hours
int minDiff = diff.Minutes; // 15 Mins
double totDiffHours = (double)hourDiff + (double)minDiff / 60; // 12.25 Hours

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...