{"id":535,"date":"2012-05-03T21:08:20","date_gmt":"2012-05-03T16:08:20","guid":{"rendered":"http:\/\/www.esearing.com\/v2010\/?p=535"},"modified":"2012-05-03T21:08:20","modified_gmt":"2012-05-03T16:08:20","slug":"date-subtraction-or-difference","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2012\/05\/date-subtraction-or-difference\/","title":{"rendered":"Date Subtraction or Difference"},"content":{"rendered":"<p>Sometimes you need to know the differences between two dates in days months years whatever.<br \/>\n<strong><br \/>\nSQL SERVER<\/strong><br \/>\n<code><br \/>\nselect datediff(day,date1, date2) as days_diff,<br \/>\ndatediff(month,date1, date2) as months_diff...<\/p>\n<p>Can also do year, quarter, week, hour, minute, and second dateparts.<br \/>\nDates can be hard coded or column names.<br \/>\n<\/code><\/p>\n<p><strong>Coldfusion Function<\/strong><br \/>\n<code><br \/>\n#DateDiff(\"datepart\", \"date1\", \"date2\")#<br \/>\ndatepart (yyyy, q, m, w, h, n, s)<br \/>\n<\/code><\/p>\n<p><strong>JavaScript<\/strong><br \/>\n<code><br \/>\nA little tricker so further research may be needed to get the expected results.<br \/>\nvar DateDiff = {<\/p>\n<p>    inDays: function(d1, d2) {<br \/>\n        var t2 = d2.getTime();<br \/>\n        var t1 = d1.getTime();<\/p>\n<p>        return parseInt((t2-t1)\/(24*3600*1000));<br \/>\n    },<br \/>\n<\/code><\/p>\n<p><strong>JQuery<\/strong><br \/>\n<code><br \/>\nvar day_diff = datediff(\"day\", date1, date2);<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to know the differences between two dates in days months years whatever. SQL SERVER select datediff(day,date1, date2) as days_diff, datediff(month,date1, date2) as months_diff&#8230; Can also do year, quarter, week, hour, minute, and second dateparts. Dates can be &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2012\/05\/date-subtraction-or-difference\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,16,12,13,24,14],"tags":[33],"class_list":["post-535","post","type-post","status-publish","format-standard","hentry","category-code","category-coldfusion","category-javascript","category-jquery","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql","tag-dates"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=535"}],"version-history":[{"count":2,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/535\/revisions"}],"predecessor-version":[{"id":537,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/535\/revisions\/537"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}