I'm working with an data set in which there is a date field with dates that look like the following:
42437.4261290278
42437.5460402431
42437.5478825116
with the larger of the numbers being the most recent. One of us believes it is relating to unix epoch and alternate time representations. The issue we are facing now is reading those date's above into standard MM-DD-YYYY format. Any one have any ideas on how to convert these alternate date forms into standard dates?
I'm trying to do this in C#. And for reference, I expect that the last two dates listed to be sometime on March 8th, 2016 and the first to be some time before then.
Following your assertion that the dates represented are 2016-03-08, I assume the start of the epoch is 1899-12-30:
static string UnixTimeStampToDateAsString(double ts)
{
DateTime epoch = new DateTime(1899, 12, 30);
DateTime d = epoch.AddDays(ts);
return (d.ToString("yyyy-MM-dd HH:mm:ss"));
}
static void Main(string[] args)
{
foreach (double dateNumber in new double[] { 42437.4261290278, 42437.5460402431, 42437.5478825116 })
{
Console.WriteLine(UnixTimeStampToDateAsString(dateNumber));
}
Console.ReadLine();
}
Outputs:
2016-03-08 10:13:37
2016-03-08 13:06:17
2016-03-08 13:08:57
I have to state that the 30th of December 1899 is a rather unlikely value, but I suppose someone might have had a "reason" to use that.
Edit Thanks to @EricLippert I can suggest this instead:
Console.WriteLine(DateTime.FromOADate(dateNumber).ToString("yyyy-MM-dd HH:mm:ss"));