DateTime.FromOADate() Method in C#


The DateTime.FromOADate() method in C# is used to return a DateTime equivalent to the specified OLE Automation Date.

Syntax

Following is the syntax −

public static DateTime FromOADate (double val);

Above, Val is the OLE Automation Date value.

Example

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

using System;
public class Demo {
   public static void Main() {
      DateTime d1 = DateTime.FromOADate(1.0);
      Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",d1);
   }
}

Output

This will produce the following output −

DateTime = 31 December 1899, 12:00:00

Example

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

using System;
public class Demo {
   public static void Main() {
      DateTime d1 = DateTime.FromOADate(375765.0);
      DateTime d2 = DateTime.FromOADate(0.0);
      Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",d1);
      Console.WriteLine("New DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",d2);
   }
}

Output

This will produce the following output −

DateTime = 21 October 2928, 12:00:00
New DateTime = 30 December 1899, 12:00:00

Updated on: 08-Nov-2019

454 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements