DateTime.ToOADate() Method in C# Last Updated : 13 Feb, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to convert the value of this instance to the equivalent OLE Automation date. Syntax: public double ToOADate (); Return Value: This method returns a double-precision floating-point number that contains an OLE Automation date equivalent to the value of this instance. Exception: OverflowException: If the value of this instance cannot be represented as an OLE Automation Date. Below programs illustrate the use of DateTime.ToOADate() Method Example 1: csharp // C# program to demonstrate the // DateTime.ToOADate() Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // creating object of DateTime DateTime date = new DateTime(2011, 1, 1, 4, 0, 15); // Converts the value of this instance to // the equivalent OLE Automation date. // using ToOADate() method; double value = date.ToOADate(); // Display the time Console.WriteLine("OLE Automation date is {0}", value); } catch (OverflowException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: OLE Automation date is 40544.1668402778 Example 2: For OverflowException csharp // C# program to demonstrate the // DateTime.ToOADate() Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // creating object of DateTime DateTime date = new DateTime(0099, 1, 1, 4, 0, 15); // Converts the value of this instance // to the equivalent OLE Automation date. // using ToOADate() method; double value = date.ToOADate(); // Display the time Console.WriteLine("OLE Automation date is {0}", value); } catch (OverflowException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: Exception Thrown: System.OverflowException Reference: https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tooadate?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article DateTime.ToOADate() Method in C# R rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp DateTime Struct Similar Reads DateTime.ToLocalTime() Method in C# This method is used to convert the value of the current DateTime object to local time. Syntax: public DateTime ToLocalTime (); Return Value: This method returns an object whose Kind property is Local, and whose value is the local time equivalent to the value of the current DateTime object, or MaxVal 2 min read DateTime.ToLongDateString() Method in C# This method is used to convert the value of the current DateTime object to its equivalent long date string representation. Syntax: public string ToLongDateString (); Return Value: This method returns a string that contains the long date string representation of the current DateTime object. Below pro 2 min read DateTime.ToFileTime() Method in C# This method is used to convert the value of the current DateTime object to a Windows file time. Syntax: public long ToFileTime (); Return Value: This method returns the value of the current DateTime object expressed as a Windows file time. Exception: This method will give ArgumentOutOfRangeException 2 min read DateTime.Subtract() Method in C# This method is used to subtract the specified time or duration from this instance. There are 2 methods in the overload list of this method as follows: Subtract(DateTime) Subtract(TimeSpan) DateTime.Subtract(DateTime) This method is used to subtract the specified date and time from this instance. Syn 3 min read DateTime.ToBinary() Method in C# This method is used to serializes the current DateTime object to a 64-bit binary value that subsequently can be used to recreate the DateTime object. Syntax: public long ToBinary (); Return Value: This method returns a 64-bit signed integer that encodes the Kind and Ticks properties. Below programs 2 min read Like