DateTime.FromBinary() Method in C# Last Updated : 11 Aug, 2021 Comments Improve Suggest changes Like Article Like Report DateTime.FromBinary(Int64) Method is used to deserialize a 64-bit binary value and recreates an original serialized DateTime object. Syntax: public static DateTime FromBinary (long dateData); Here, it takes a 64-bit signed integer that encodes the Kind property in a 2-bit field and the Ticks property in a 62-bit field.Return Value: This method returns an object that is equivalent to the DateTime object that was serialized by the ToBinary() method.Exception: This method will give ArgumentException if the dateData is less than MinValue or greater than MaxValue. Below programs illustrate the use of DateTime.FromBinary(Int64) Method:Example 1: csharp // C# program to demonstrate the // DateTime.FromBinary(Int64) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // creating object of DateTime DateTime date1 = new DateTime(2010, 1, 1, 8, 0, 15); // getting a 64-bit signed integer // using ToBinary() method long binLocal = date1.ToBinary(); // converting 64-bit into DateTime format // using FromBinary() method DateTime date2 = DateTime.FromBinary(binLocal); // Display the date1 System.Console.WriteLine("DateTime before " + "operation: {0:y} {0:dd}",date1); // Display the date2 System.Console.WriteLine("\nDateTime after" + " operation: {0:y} {0:dd}", date2); } catch (ArgumentOutOfRangeException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: DateTime before operation: 2010 January 01 DateTime after operation: 2010 January 01 Example 2: For ArgumentOutOfRangeException csharp // C# program to demonstrate the // DateTime.FromBinary() Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // converting 64-bit into DateTime format // using FromBinary() method DateTime date = DateTime.FromBinary(-100000000000000000); // Display the date System.Console.WriteLine("\nDateTime: + {0:y} {0:dd} ", date); } catch (ArgumentException e) { Console.WriteLine("The resulting dateData" + " is less than the MinValue "); Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: The resulting dateData is less than the MinValue Exception Thrown: System.ArgumentException Reference: https://docs.microsoft.com/en-us/dotnet/api/system.datetime.frombinary?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article DateTime.FromBinary() Method in C# rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp DateTime Struct Similar Reads DateTime.FromOADate() Method in C# DateTime.FromOADate(Double) Method is used to return a DateTime equivalent to the specified OLE Automation Date. Syntax: public static DateTime FromOADate (double d); Here, it takes an OLE Automation Date value. Return Value: This method returns an object that represents the same date and time as d. 2 min read DateTime.FromFileTime() Method in C# DateTime.FromFileTime(Int64) Method is used to converts the specified Windows file time to an equivalent local time. Syntax: public static DateTime FromFileTime (long fileTime); Here, it takes a Windows file time expressed in ticks. Return Value: This method returns an object that represents the loc 2 min read DateTime.FromFileTimeUtc() Method in C# DateTime.FromFileTimeUtc(Int64) Method is used to convert the specified Windows file time to an equivalent UTC time. Syntax: public static DateTime FromFileTimeUtc (long fileTime); Here, it takes a Windows file time expressed in ticks.Return Value: This method returns an object that represents the U 2 min read DateTimeOffset.FromFileTime() Method in C# DateTimeOffset.FromFileTime(Int64) Method is used to convert the specified Windows file time to an equivalent local time. Syntax: public static DateTimeOffset FromFileTime (long fileTime); Here, it takes a Windows file time, expressed in ticks. Return Value: This method returns an object that repres 2 min read DateTime.Add() Method in C# This method is used to return a new DateTime that adds the value of the specified TimeSpan to the value of this instance. Syntax: public DateTime Add (TimeSpan value); Here, value is a positive or negative time interval. Return Value: This method returns an object whose value is the sum of the date 2 min read DateTime.GetTypeCode() Method in C# This method is used to return the TypeCode for value type DateTime. Syntax: public TypeCode GetTypeCode (); Return Value: This method returns the enumerated constant, DateTime. Below programs illustrate the use of DateTime.GetTypeCode() Method Example 1: csharp // C# program to demonstrate the // Da 1 min read DateTime.GetHashCode() Method in C# This method is used to return the hash code for this instance. Syntax: public override int GetHashCode (); Return Value: This method returns a 32-bit signed integer hash code. Below programs illustrate the use of DateTime.GetHashCode() Method: Example 1: csharp // C# program to demonstrate the // Da 1 min read DateTimeOffset.FromUnixTimeSeconds() Method in C# DateTimeOffset.FromUnixTimeSeconds(Int64) Method is used to convert a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a DateTimeOffset value. Syntax: public static DateTimeOffset FromUnixTimeSeconds (long seconds); Here, it takes a Unix time, expressed as 2 min read DateTime.AddDays() Method in C# This method is used to return a new DateTime that adds the specified number of days to the value of this instance. Syntax: public DateTime AddDays (double value); Here, the value is the number of whole and fractional days. The value parameter can be negative or positive. Return Value: This method re 2 min read DateTime.Compare() Method in C# This method is used to compare two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance. Syntax: public static int Compare (DateTime t1, DateTime t2); Parameters: t1: The first object to compare. t2: Th 2 min read Like