{"id":186,"date":"2017-07-31T02:02:04","date_gmt":"2017-07-31T02:02:04","guid":{"rendered":"http:\/\/info.juliusgoh.life\/?p=186"},"modified":"2018-01-09T04:56:47","modified_gmt":"2018-01-09T04:56:47","slug":"create-daterange-using-function","status":"publish","type":"post","link":"https:\/\/info.juliusgoh.life\/?p=186","title":{"rendered":"Create daterange using function"},"content":{"rendered":"<pre>function createDateRangeArray($strDateFrom,$strDateTo)\r\n{\r\n\/\/ takes two dates formatted as YYYY-MM-DD and creates an\r\n\/\/ inclusive array of the dates between the from and to dates.\r\n\r\n\/\/ could test validity of dates here but I'm already doing\r\n\/\/ that in the main script\r\n\r\n$aryRange=array();\r\n\r\n$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));\r\n$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));\r\n\r\nif ($iDateTo&gt;=$iDateFrom)\r\n{\r\narray_push($aryRange,date('Y-m-d',$iDateFrom)); \/\/ first entry\r\nwhile ($iDateFrom&lt;$iDateTo)\r\n{\r\n$iDateFrom+=86400; \/\/ add 24 hours\r\narray_push($aryRange,date('Y-m-d',$iDateFrom));\r\n}\r\n}\r\nreturn $aryRange;\r\n}\r\n<\/pre>\n<p>EX usage:<\/p>\n<pre>$fromDate = '2017-07-01';\r\n$toDate = '2017-07-03';\r\n\r\n\/\/Create Date range\r\n$dateDay = createDateRangeArray($fromDate,$toDate);\r\n\r\n\/\/Initialize all data to 0\r\nforeach($dateDay as $tmp){\r\n$arraydate[$tmp]['total_distinct'] = 0;\r\n$arraydate[$tmp]['total'] = 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>function createDateRangeArray($strDateFrom,$strDateTo) { \/\/ takes two dates formatted as YYYY-MM-DD and creates an \/\/ inclusive array of the dates between the from and to dates. \/\/ could test validity of dates here but I&#8217;m already doing \/\/ that in the main script $aryRange=array(); $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4)); $iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4)); if ($iDateTo&gt;=$iDateFrom) { array_push($aryRange,date(&#8216;Y-m-d&#8217;,$iDateFrom)); \/\/ first entry while [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":223,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/186"}],"collection":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":4,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/media\/223"}],"wp:attachment":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}