DateTime.ToOADate() Method in C#
Last Updated :
13 Feb, 2019
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:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
try {
DateTime date = new DateTime(2011, 1,
1, 4, 0, 15);
double value = date.ToOADate();
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
using System;
using System.Globalization;
class GFG {
public static void Main()
{
try {
DateTime date = new DateTime(0099, 1,
1, 4, 0, 15);
double value = date.ToOADate();
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:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...