{"id":1434,"date":"2023-08-24T16:15:54","date_gmt":"2023-08-24T15:15:54","guid":{"rendered":"https:\/\/ibex.tech\/c\/?p=1434"},"modified":"2023-08-25T17:51:09","modified_gmt":"2023-08-25T16:51:09","slug":"comparing-date-and-time","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/c\/datetime\/comparing-date-and-time","title":{"rendered":"Comparing date and time"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Compare tm&#8217;s<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tstruct tm Tm1 = {0};\n\tstruct tm Tm2 = {0};\n\n\tstrptime(\"2020-08-29 11:05:13\", \"%Y-%m-%d %H:%M:%S\", &amp;Tm1);\n\tstrptime(\"2020-08-29 11:05:16\", \"%Y-%m-%d %H:%M:%S\", &amp;Tm2);\n\n\tif (mktime(&amp;Tm1) >= mktime(&amp;Tm2))\t\t\/\/Larger values of mktime() are more recent in time\n\t{\n\t\tprintf(\"Tm1 is more recent than Tm2\\n\");\n\t}\n\telse\n\t{\n\t\tprintf(\"Tm1 is older than Tm2\\n\");\n\t}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">or with strptime() check<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\tstruct tm Tm1 = {0};\n\tstruct tm Tm2 = {0};\n\n\tif (strptime(\"2020-08-29 11:05:13\", \"%Y-%m-%d %H:%M:%S\", &amp;Tm1) == NULL)\n\t\tprintf(\"strptime Failed\\n\");\n\n\tif (strptime(\"2020-08-29 11:05:16\", \"%Y-%m-%d %H:%M:%S\", &amp;Tm2) == NULL)\n\t\tprintf(\"strptime Failed\\n\");\n\n\tif (mktime(&amp;Tm1) >= mktime(&amp;Tm2))\t\t\/\/Larger values of mktime() are more recent in time\n\t{\n\t\tprintf(\"Tm1 is more recent than Tm2\\n\");\n\t}\n\telse\n\t{\n\t\tprintf(\"Tm1 is older than Tm2\\n\");\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get time difference in seconds<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tdouble TimeDifferenceSeconds;\n\n\tTimeDifferenceSeconds = difftime(mktime(&amp;Tm1), mktime(&amp;Tm2));\t\/\/Value1 - Value2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Compare tm&#8217;s or with strptime() check Get time difference in seconds<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118],"tags":[],"class_list":["post-1434","post","type-post","status-publish","format-standard","hentry","category-datetime"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=1434"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1434\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1434\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=1434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=1434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=1434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}