Hey guys!
The DST are a real pain in the ass for all developers.
But I have got a little something for you! A DateTime extension method which will return the number of hours for the current Date.
public static int GetNumberOfActualHours(this DateTime dateTime) { var hours = 24; var start = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 1, 0, 0, DateTimeKind.Local); var end = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 4, 0, 0, DateTimeKind.Local); if ((!start.IsDaylightSavingTime()) && (end.IsDaylightSavingTime())) hours--; else if ((start.IsDaylightSavingTime()) && (!end.IsDaylightSavingTime())) hours++; return (hours); }
Happy coding!