Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.ToOADate - Time only

Tags:

c#

I have a "DateTime" var with the current date (DateTime.Now). I can convert this to a OADate-Format (41392,524432) as example. But how I can convert this, that I'm just getting the time without the date? For example 1 minute and 4 seconds (01:04) are 0,04444444 in this format.

like image 565
namespace Avatar asked Oct 24 '25 06:10

namespace


1 Answers

Since MSDN states that:

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899

you presumably want to use that as your base date:

DateTime oaBaseDate = new DateTime(1899,12,30);
double result = oaBaseDate.Add(DateTime.Now.TimeOfDay).ToOADate();

or if you don't like magic numbers (magic dates), the equivalent:

DateTime oaBaseDate = DateTime.FromOADate(0);
double result = oaBaseDate.Add(DateTime.Now.TimeOfDay).ToOADate();
like image 96
Joe Avatar answered Oct 26 '25 19:10

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!