DateTime.ToOADate() Method in C#


The DateTime.ToOADate() method in C# is used to convert the value of this instance to the equivalent OLE Automation date.

Syntax

Following is the syntax −

public double ToOADate ();

Example

Let us now see an example to implement the DateTime.ToOADate() method −

using System;
public class Demo {
   public static void Main() {
      DateTime d = new DateTime(2019, 10, 11, 9, 10, 35);
      Console.WriteLine("Date = {0}", d);
      double res = d.ToOADate();
      Console.WriteLine("OLE Automation date = {0}", res);
   }
}

Output

This will produce the following output −

Date = 10/11/2019 9:10:35 AM
OLE Automation date = 43749.382349537

Example

Let us now see another example to implement the DateTime.ToOADate() method −

using System;
public class Demo {
   public static void Main() {
      DateTime d = DateTime.Now;
      Console.WriteLine("Date = {0}", d);
      double res = d.ToOADate();
      Console.WriteLine("OLE Automation date = {0}", res);
   }
}

Output

This will produce the following output −

Date = 10/16/2019 8:50:25 AM
OLE Automation date = 43754.3683518634
raja
Published on 08-Nov-2019 11:06:20
Advertisements