{"id":411,"date":"2019-11-20T14:41:57","date_gmt":"2019-11-20T14:41:57","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=411"},"modified":"2022-02-17T06:24:14","modified_gmt":"2022-02-17T06:24:14","slug":"timespan-and-calculating-time-difference","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/date-and-time\/timespan-and-calculating-time-difference","title":{"rendered":"TimeSpan and Calculating Time Difference"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">How many hours\/minutes\/seconds\/etc have elapsed<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tTimeSpan TimeElapsed = DateTime.Now - DateTime1;\n\tint MinutesElapsed = (int)TimeElapsed.TotalMinutes;     \/\/Note that TimeElapsed.Minutes gives you minutes as 0-59, not total minutes<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Add or subtract a TimeSpan from a DateTime<\/h4>\n\n\n\n<p>Don&#8217;t use timespan, just use AddHours etc:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tMyDateTime = MyDateTime.AddHours(2);\n\tMyDateTime = MyDateTime.AddHours(-2);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How many hours\/minutes\/seconds\/etc have elapsed Add or subtract a TimeSpan from a DateTime Don&#8217;t use timespan, just use AddHours etc:<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-411","post","type-post","status-publish","format-standard","hentry","category-date-and-time"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/411\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}