{"id":89407,"date":"2023-05-17T07:00:24","date_gmt":"2023-05-17T05:00:24","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=89403"},"modified":"2024-02-01T15:50:33","modified_gmt":"2024-02-01T14:50:33","slug":"csharp-compare-datetime","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-compare-datetime\/","title":{"rendered":"Compare DateTime in C#"},"content":{"rendered":"<p>In C#, several methods and operators are available to compare DateTime. In this article, we will learn about them along with the best practices.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/dotnet-datetime\/CompareDateTimeInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>However, before we jump right into the different ways of comparing <code>DateTime<\/code>, let&#8217;s first get an overview of what <code>DateTime<\/code> struct is.<\/p>\n<h2><a id=\"dateTime\"><\/a>DateTime in C#<\/h2>\n<p>In C#, the\u00a0<a href=\"https:\/\/code-maze.com\/?s=datetime\" target=\"_blank\" rel=\"noopener\">DateTime<\/a> struct is a crucial component for handling date and time values.<\/p>\n<p><strong>It stores precise date and time information using a 64-bit integer value (ticks). It also provides us the ability to manipulate, format, and perform arithmetic operations on <code>DateTime<\/code> objects.<\/strong><\/p>\n<p>We have methods such as <code>ToString()<\/code> to present <code>DateTime<\/code> values in specific string representations, and methods like <code>Add<\/code> and <code>Subtract<\/code>, to manipulate the <code>DateTime<\/code> objects.<\/p>\n<h2><a id=\"comparison\"><\/a>Compare DateTime in C#<\/h2>\n<p>Comparing <code>DateTime<\/code> values are essential for a wide range of applications. C# provides several methods and operators for comparing <code>DateTime<\/code> values, including the <code>Equals()<\/code> method, the <code>Compare()<\/code> method, the <code>CompareTo()<\/code> method, and the various comparison operators.<\/p>\n<p>The <code>Equals<\/code>\u00a0method checks if two <code>DateTime<\/code> values are equal. Meanwhile, <code>Compare()<\/code> and <code>CompareTo()<\/code> methods return an integer indicating the relative values of two <code>DateTime<\/code> objects. The comparison operators <code>&lt;<\/code>, <code>&gt;<\/code>, <code>&lt;=<\/code>, and <code>&gt;=<\/code> provide a quick and easy way to compare two <code>DateTime<\/code> values.<\/p>\n<p>Let&#8217;s look at all of these in more detail.<\/p>\n<h3><a id=\"compare\"><\/a>Compare(DateTime, DateTime)<\/h3>\n<p><strong>The <code>Compare(DateTime, DateTime)<\/code> method in the <code>DateTime<\/code> struct returns an integer value that represents the relative values of two <code>DateTime<\/code> objects.<\/strong><\/p>\n<p>This method returns the integer values based on these conditions:<\/p>\n<ul>\n<li>The first <code>DateTime<\/code> object is earlier than the second, it returns a negative value<\/li>\n<li>The first <code>DateTime<\/code> object is later than the second, it returns a positive value<\/li>\n<li>The two <code>DateTime<\/code> objects are equal, it returns zero<\/li>\n<\/ul>\n<p>Let&#8217;s understand it with an example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstDate = new DateTime(2023, 5, 1);\r\nvar secondDate = new DateTime(2023, 5, 2);\r\n\r\nvar result = DateTime.Compare(firstDate, secondDate);<\/pre>\n<h3><a id=\"compareToDateTime\"><\/a>CompareTo(DateTime)<\/h3>\n<p><strong>Similar to the <code>Compare()<\/code> method, the <code>CompareTo(DateTime)<\/code> method\u00a0also returns an integer value that represents the relative values of two <code>DateTime<\/code> objects.<\/strong><\/p>\n<p>The criteria on which this method returns the integer value is the same as the <code>Compare()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstDate = new DateTime(2023, 5, 1);\r\nvar secondDate = new DateTime(2023, 5, 2);\r\n\r\nvar result = firstDate.CompareTo(secondDate);<\/pre>\n<h3><a id=\"compareToObject\"><\/a>CompareTo(Object)<\/h3>\n<p><strong>The <code>CompareTo(Object)<\/code> method\u00a0takes an object as a parameter and returns an integer value that represents the relative values of the <code>DateTime<\/code> object and the other object.<\/strong><\/p>\n<p>The criteria on which this method returns the integer value is the same as the <code>Compare()<\/code> and <code>CompareTo()<\/code> methods:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstDate = new DateTime(2023, 5, 1);\r\nobject objectDateTime = new DateTime(2023, 5, 3);\r\n\r\nvar result = firstDate.CompareTo(objectDateTime);<\/pre>\n<p>This method will attempt to convert the other object to a <code>DateTime<\/code> object and then compare its value to the value of the original <code>DateTime<\/code> object. <strong>If the other object is not a <code>DateTime<\/code> object, the method will throw an<\/strong> <code>ArgumentException<\/code>.<\/p>\n<p>This method is useful in situations where it is necessary to compare a <code>DateTime<\/code> object to another object that may not be a <code>DateTime<\/code> object, such as when comparing dates stored in different formats.<\/p>\n<h3><a id=\"equals\"><\/a>Equals(DateTime)<\/h3>\n<p><strong>The <code>Equals(DateTime)<\/code> method in C# is used to determine whether two <code>DateTime<\/code> objects are equal.<\/strong><\/p>\n<p>When using <code>DateTime.Equals(DateTime)<\/code>, it is important to keep in mind that the method compares the values of the date and time components at a resolution of one tick (100 nanoseconds). This means that two <code>DateTime<\/code> objects may have different tick values but still represent the same date and time, leading to unexpected results when using the <code>==<\/code> or <code>!=<\/code> operators.<\/p>\n<p>To avoid this issue, it is recommended that we use the <code>DateTime.Equals(DateTime)<\/code> method for comparing <code>DateTime<\/code> objects over relational operators.<\/p>\n<p>This method compares the <code>DateTime<\/code> objects based on their date and time components, rather than their ticks values, and returns <code>true<\/code> if they represent the same date and time, and <code>false<\/code> otherwise:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void DateTimeComparisonWithEquals(DateTime firstDate, DateTime secondDate)\r\n{\r\n    if (firstDate.Equals(secondDate))\r\n    {\r\n        Console.WriteLine($\"{firstDate} is the same as {secondDate}\");\r\n    }\r\n    else\r\n    {\r\n        Console.WriteLine($\"{firstDate} is not the same as {secondDate}\");\r\n    }\r\n}<\/pre>\n<h3><a id=\"relationalOperators\"><\/a>DateTime Comparison Using Relational Operators<\/h3>\n<p>In C#, <code>DateTime<\/code> objects can be compared using relational operators like <code>&lt;<\/code>, <code>&lt;=<\/code>, <code>&gt;<\/code>, and <code>&gt;=<\/code>. <strong>These operators compare the date and time components of two <code>DateTime<\/code> objects and return a <code>Boolean<\/code> value indicating whether the comparison is true or false:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void DateTimeComparisonWithRelationalOperator(DateTime firstDate, DateTime secondDate)\r\n{\r\n    if (firstDate &lt; secondDate)\r\n    {\r\n        Console.WriteLine($\"{firstDate} is earlier than {secondDate}\");\r\n    }\r\n    else if (firstDate &gt; secondDate)\r\n    {\r\n        Console.WriteLine($\"{firstDate} is later than {secondDate}\");\r\n    }\r\n    else\r\n    {\r\n        Console.WriteLine($\"{firstDate} is the same as {secondDate}\");\r\n    }\r\n}<\/pre>\n<p>Relational operators can also be combined with the <code>DateTime.Equals()<\/code> method to check if a <code>DateTime<\/code> object falls within a certain range of dates.<\/p>\n<h2><a id=\"best\"><\/a>Best Practices To Compare DateTime<\/h2>\n<p><strong>Ideally, we should use the <code>DateTime.Compare()<\/code> method for comparing two <code>DateTime<\/code> objects.\u00a0<\/strong>Using <code>DateTime.Compare()<\/code> ensures that precision issues are taken into account when comparing <code>DateTime<\/code> objects.<\/p>\n<p>We should use the UTC time zone when working with <code>DateTime<\/code> objects to avoid issues with time zone differences:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static bool IsDateInSameTimeZone()\r\n{\r\n    var firstDate = new DateTime(2021, 05, 06, 12, 0, 0, DateTimeKind.Local);\r\n    var secondDate = new DateTime(2021, 05, 06, 12, 0, 0, DateTimeKind.Utc);\r\n    var firstDateAsUtc = firstDate.ToUniversalTime();\r\n            \r\n    if(firstDateAsUtc.Equals(secondDate))\r\n    {\r\n        return true;\r\n    }\r\n    return false;\r\n}<\/pre>\n<p><strong>We should avoid comparing <code>DateTime<\/code> objects using the <code>==<\/code> or <code>!=<\/code> operators<\/strong> as <code>DateTime<\/code> objects have a finite level of precision, and comparing two <code>DateTime<\/code> objects that have different time components using the <code>==<\/code> or <code>!=<\/code> operators can produce unexpected results, even if the two objects represent the same point in time:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static bool IsDatePrecisionSame() \r\n{\r\n    var firstDate = new DateTime(2021, 05, 06, 12, 0, 0);\r\n    var secondDate = new DateTime(2021, 05, 06, 12, 0, 0, 500);\r\n\r\n    if(firstDate == secondDate)\r\n    {\r\n        return true;\r\n    }\r\n    return false;\r\n}<\/pre>\n<p>Here, <code>firstDate<\/code> \u00a0and <code>secondDate<\/code> represent the same point in time, but with different levels of precision. When comparing the two <code>DateTime<\/code> objects using the <code>==<\/code> operator, the result is <code>false<\/code>.<\/p>\n<p>When comparing <code>DateTime<\/code> objects to determine if one is earlier or later than another, we should use the <code>DateTime<\/code> properties like <code>DateTime.Ticks<\/code> and <code>DateTime.CompareTo()<\/code> method to compare them with better precision.<\/p>\n<p>When checking if a <code>DateTime<\/code> object is within a certain range, we should the\u00a0<code>DateTime.CompareTo()<\/code> method and relational operators like <code>&lt;<\/code> and <code>&gt;<\/code> to compare them.<\/p>\n<p><strong>We should be aware of potential issues like leap years and daylight saving time and adjust our code accordingly.<\/strong><\/p>\n<p>By following these best practices, we can ensure that our <code>DateTime<\/code> comparisons are accurate and reliable, which is crucial for building robust and high-quality applications.<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>In this article, we learned about <code>DateTime<\/code> struct, different ways to compare <code>DateTime<\/code> with some examples and best practices for <code>DateTime<\/code> comparison in C#.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C#, several methods and operators are available to compare DateTime. In this article, we will learn about them along with the best practices. However, before we jump right into the different ways of comparing DateTime, let&#8217;s first get an overview of what DateTime struct is. DateTime in C# In C#, the\u00a0DateTime struct is a [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,1049],"tags":[1172,1781,1782],"class_list":["post-89407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-datetime","tag-compare","tag-compareto","tag-datetime-comparasion","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Compare DateTime in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-compare-datetime\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compare DateTime in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-compare-datetime\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-17T05:00:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-01T14:50:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Compare DateTime in C#\",\"datePublished\":\"2023-05-17T05:00:24+00:00\",\"dateModified\":\"2024-02-01T14:50:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/\"},\"wordCount\":836,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"Compare\",\"CompareTo\",\"DateTime Comparasion\"],\"articleSection\":[\"C#\",\"DateTime\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-compare-datetime\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/\",\"url\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/\",\"name\":\"Compare DateTime in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-05-17T05:00:24+00:00\",\"dateModified\":\"2024-02-01T14:50:33+00:00\",\"description\":\"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-compare-datetime\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-compare-datetime\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Compare DateTime in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Compare DateTime in C# - Code Maze","description":"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-compare-datetime\/","og_locale":"en_US","og_type":"article","og_title":"Compare DateTime in C# - Code Maze","og_description":"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.","og_url":"https:\/\/code-maze.com\/csharp-compare-datetime\/","og_site_name":"Code Maze","article_published_time":"2023-05-17T05:00:24+00:00","article_modified_time":"2024-02-01T14:50:33+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Compare DateTime in C#","datePublished":"2023-05-17T05:00:24+00:00","dateModified":"2024-02-01T14:50:33+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/"},"wordCount":836,"commentCount":2,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["Compare","CompareTo","DateTime Comparasion"],"articleSection":["C#","DateTime"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-compare-datetime\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/","url":"https:\/\/code-maze.com\/csharp-compare-datetime\/","name":"Compare DateTime in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-05-17T05:00:24+00:00","dateModified":"2024-02-01T14:50:33+00:00","description":"To compare DateTime values in C#, there are several methods and operators available to perform the comparison.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-compare-datetime\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-compare-datetime\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Compare DateTime in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/89407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=89407"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/89407\/revisions"}],"predecessor-version":[{"id":90003,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/89407\/revisions\/90003"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=89407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=89407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=89407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}