{"id":501,"date":"2008-06-04T00:00:00","date_gmt":"2008-06-03T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=501"},"modified":"2011-07-15T09:32:29","modified_gmt":"2011-07-15T01:32:29","slug":"get-working-day-difference-for-2-dates","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=501","title":{"rendered":"Get Working day difference for 2 dates"},"content":{"rendered":"<p><P>CREATE <A href=\"mailto:DEFINER=`root`@`%\">DEFINER=`root`@`%<\/A>` FUNCTION `getworkdaydiff`(b date, a date) RETURNS int(11)<BR>DETERMINISTIC<BR>COMMENT &#8216;Get Working day difference for 2 dates&#8217;<BR>BEGIN<BR>DECLARE freedays int;<BR>SET freedays = 0;<\/P><br \/>\n<P>SET @x = DATEDIFF(b, a);<BR>IF @x&lt;0 THEN<BR>SET @m = a;<BR>SET a = b;<BR>SET b = @m;<BR>SET @m = -1;<BR>ELSE<BR>SET @m = 1;<BR>END IF;<BR>SET @x = abs(@x) + 1;<BR>\/* days in first week *\/<BR>SET @w1 = WEEKDAY(a)+1;<BR>SET @wx1 = <A href=\"mailto:8-@w1\">8-@w1<\/A>;<BR>IF @w1&gt;5 THEN <BR>SET @w1 = 0;<BR>ELSE<BR>SET @w1 = <A href=\"mailto:6-@w1\">6-@w1<\/A>; <BR>END IF;<BR>\/* days in last week *\/<BR>SET @wx2 = WEEKDAY(b)+1;<BR>SET @w2 = @wx2;<BR>IF @w2&gt;5 THEN <BR>SET @w2 = 5;<BR>END IF;<BR>\/* summary *\/<BR>SET @weeks = (@x-@wx1-@wx2)\/7;<BR>SET @noweekends = (@weeks*5)+@w1+@w2;<BR>SET @result = @noweekends-freedays;<BR>RETURN @result*@m;<BR>END<\/P><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CREATE DEFINER=`root`@`%` FUNCTION `getworkdaydiff`(b date, a date) RETURNS int(11)DETERMINISTICCOMMENT &#8216;Get Working day difference for 2 dates&#8217;BEGINDECLARE freedays int;SET freedays = 0; SET @x = DATEDIFF(b, a);IF @x&lt;0 THENSET @m = a;SET a = b;SET b = @m;SET @m = -1;ELSESET @m = 1;END IF;SET @x = abs(@x) + 1;\/* days in first week *\/SET @w1 &hellip; <a href=\"https:\/\/www.strongd.net\/?p=501\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Get Working day difference for 2 dates<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[93],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-date"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=501"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}