C# DateTime ToOADate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.ToOADate() returns a double. The whole part is the number of days since December 30, 1899. The fraction is the time of day: 0.5 is noon and 0.25 is 6 AM.

Excel and COM use this style of number, so it is handy when you write dates to spreadsheets. Use DateTime.FromOADate to turn the number back into a date.

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToOADate(...). DateTime is a struct, so every value is copied and never changed in place.

Syntax

Call it on a DateTime. It takes no arguments.

C#
DateTime dt = new DateTime(2026, 11, 18, 12, 0, 0);
double oa = dt.ToOADate();                 // 46344.5
DateTime back = DateTime.FromOADate(oa);   // same date
CallWhat it does
dt.ToOADate()Days since 1899-12-30 as a double.
new DateTime(1899, 12, 30).ToOADate()The origin, 0.
DateTime.FromOADate(oa)The opposite direction.

Print the number with ToString(CultureInfo.InvariantCulture) so the decimal point is always a dot.

Library declarations
C#
public double ToOADate();

Parameters

ParameterDescription
NoneToOADate() takes no parameters.

Return Value

Return ValueDescription
doubleThe OLE Automation date: whole days since December 30, 1899, plus the time of day as a fraction.

C# Examples

Example 1 — Day Zero and Day One

Show the OA date for December 30 and 31, 1899.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(new DateTime(1899, 12, 30).ToOADate());
        Console.WriteLine(new DateTime(1899, 12, 31).ToOADate());
    }
}

How It Works

  1. Origin. December 30, 1899 is the starting day, so the value is 0.
  2. Next day. December 31 is one whole day later, so the value is 1.
  3. Whole numbers. A double that has no fraction prints without a decimal point.
  4. Midnight times. Both dates are at 00:00:00, so the fraction is zero.

Example 2 — Date, Noon, and Six AM

Convert November 18, 2026 at three times of day.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        CultureInfo inv = CultureInfo.InvariantCulture;
        Console.WriteLine(new DateTime(2026, 11, 18).ToOADate().ToString(inv));
        Console.WriteLine(new DateTime(2026, 11, 18, 12, 0, 0).ToOADate().ToString(inv));
        Console.WriteLine(new DateTime(2026, 11, 18, 6, 0, 0).ToOADate().ToString(inv));
    }
}

How It Works

  1. Day count. November 18, 2026 is day 46344 after December 30, 1899.
  2. Noon. Twelve hours is half a day, so the fraction is .5.
  3. Six AM. Six hours is a quarter of a day, so the fraction is .25.
  4. Invariant text. The invariant culture keeps the decimal separator a dot on every computer.

Example 3 — Exact and Lossy Round Trips

Round trip a clean value and one with a tiny extra tick count.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        DateTime dt = new DateTime(2028, 2, 29, 18, 0, 0);
        double oa = dt.ToOADate();
        Console.WriteLine(oa.ToString(CultureInfo.InvariantCulture));
        Console.WriteLine(DateTime.FromOADate(oa) == dt);

        DateTime fine = new DateTime(2026, 11, 18, 14, 30, 45).AddTicks(5);
        Console.WriteLine(DateTime.FromOADate(fine.ToOADate()) == fine);
    }
}

How It Works

  1. Leap day at 6 PM. February 29, 2028 at 18:00 is day 46812 plus three quarters of a day.
  2. Clean round trip. The value has no extra ticks, so converting back gives an equal date.
  3. Five extra ticks. That is half a microsecond, finer than the millisecond resolution of an OA date.
  4. Lossy. The tiny part is lost on the way, so the last comparison prints False.

Frequently Asked Questions

A double with days since December 30, 1899 and the time of day as a fraction.
For dates after March 1, 1900, yes. Excel serial numbers match OA dates.
OA dates keep only whole milliseconds, so finer ticks are lost.
The whole day number plus 0.5.
Dates before year 100 throw OverflowException.

Next: ToShortDateString()

Get the date part as short text using the current culture's short date pattern with System.DateTime.

ToShortDateString() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful