Hope this helps:
public class UlTime
{
#region Constants
public const long TICKS_IN_A_SECOND = 10000000;
public const int SECONDS_IN_A_DAY = 86400;
public const int SECONDS_IN_A_HOUR = 3600;
public const int SECONDS_IN_A_MINUTE = 60;
public const int MINUTES_IN_A_DAY = 1440;
public const int MINUTES_IN_A_HOUR = 60;
#endregion
#region TimeSpan to/from double
/// <summary>Converts a double into a timespan.</summary>
/// <param name="dValue">A double where the whole number part is days
and
/// the decimal portion represents some fraction of a day</param>
/// <returns>A Timespan.</returns>
public static TimeSpan DoubleToTimeSpan(double dValue)
{
int iDays = (int) dValue;
double dSeconds = Math.Floor( UlTime.SECONDS_IN_A_DAY * (dValue -
iDays) );
return new TimeSpan(iDays, 0, 0, (int) dSeconds, 0);
}
public static double TimeSpanToDouble( TimeSpan tsValue )
{
double dResult = tsValue.TotalSeconds / UlTime.SECONDS_IN_A_DAY;
return dResult;
}
#endregion
#region DateTime to/from double
/// <summary>Double to DateTime.</summary>
/// <param name="dValue">A double that represents time starting
/// on December 30, 1899 at midnight. The whole number part is days
and the
/// decimal portion represents some fraction of a day.</param>
/// <returns>A DateTime</returns>
public static DateTime DoubleToDateTime(double dValue)
{
DateTime dtResult = new DateTime(1899, 12, 30, 0, 0, 0, 0);
dtResult += DoubleToTimeSpan(dValue);
return dtResult;
}
/// <summary>Converts a datetime into a double.</summary>
/// <param name="dtValue">A C# datetime, which is value type that
represents
/// dates and times with values ranging from 12:00:00 midnight,
January 1, 0001
/// Anno Domini (Common Era) to 11:59:59 P.M., December 31, 9999 A.D.
(C.E.)</param>
/// <returns>A double that represents time starting on December 30,
1899
/// at midnight. The whole number part is days and the decimal
portion represents
/// some fraction of a day.</returns>
public static double DateTimeToDouble( DateTime dtValue )
{
TimeSpan tsTemp = dtValue - new DateTime(1899, 12, 30, 0, 0, 0, 0);
double dResult = tsTemp.TotalSeconds / UlTime.SECONDS_IN_A_DAY;
return( dResult );
}
#endregion
}
Dave