{"id":2869,"date":"2020-05-29T06:20:43","date_gmt":"2020-05-29T05:20:43","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2869"},"modified":"2022-02-17T07:13:48","modified_gmt":"2022-02-17T07:13:48","slug":"day-names","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/date-and-time\/useful-code\/day-names","title":{"rendered":"Day Names"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Get # day names from DateTime and into the past<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/*************************************************\n\/\/*************************************************\n\/\/********** GET X DAY NAMES IN THE PAST **********\n\/\/*************************************************\n\/\/*************************************************\n\/\/$DayChangeHour\n\/\/  Normally 0.  Set to 2 is say you want your day to change at 2am instead of midnight (i.e. you'd stil view 01:59 as the evening of the day before)\n\/\/$DayNameChar\n\/\/  'D' = Mon through Sun, 'l' = \tSunday through Saturday\n\/\/Returns an array:\n\/\/  &#91;0] Todays day name\n\/\/  &#91;1] Previous day name\n\/\/  &#91;#] etc\n\/* Example usage\n  $DayNames = GetXDayNamesInThePast($ServerTimeNow, 7, \"D\", 4);\n  print_r($DayNames);\n*\/\nfunction GetXDayNamesInThePast ($DateTimeNow, $NumberOfPastDayNames, $DayNameChar, $DayChangeHour)\n{\n  $Output = array();\n  \n  \n  $DateTimeNow = strtotime($DateTimeNow);\n\n  \/\/----- ARE WE INTO A NEW DAY? -----\n  if ( intval((date('G', $DateTimeNow))) >= $DayChangeHour )\n  {\n    \/\/WE ARE INTO THE NEW DAY\n    \n  }\n  else\n  {\n    \/\/WE ARE STILL PART OF YESTERDAY (e.g. its 1am)\n    $DateTimeNow = strtotime('-1 day',$DateTimeNow);\n  }\n  \n  \/\/----- FILL THE ARRAY WITH THE DAY NAMES -----\n  $Output&#91;] = date($DayNameChar, $DateTimeNow);\n  while ($NumberOfPastDayNames--)\n  {\n    $DateTimeNow = strtotime('-1 day',$DateTimeNow);\n    $Output&#91;] = date($DayNameChar, $DateTimeNow);\n  }\n  \n  return($Output);\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get # day names from DateTime and into the future<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/***************************************************\n\/\/***************************************************\n\/\/********** GET X DAY NAMES IN THE FUTURE **********\n\/\/***************************************************\n\/\/***************************************************\n\/\/$DayChangeHour\n\/\/  Normally 0.  Set to 2 is say you want your day to change at 2am instead of midnight (i.e. you'd stil view 01:59 as the evening of the day before)\n\/\/$DayNameChar\n\/\/  'D' = Mon through Sun, 'l' = \tSunday through Saturday\n\/\/Returns an array:\n\/\/  &#91;0] Todays day name\n\/\/  &#91;1] Next day name\n\/\/  &#91;#] etc\n\/* Example usage\n  $DayNames = GetXDayNamesInThePast($ServerTimeNow, 7, \"D\", 4);\n  print_r($DayNames);\n*\/\nfunction GetXDayNamesInTheFuture ($DateTimeNow, $NumberOfFutureDayNames, $DayNameChar, $DayChangeHour)\n{\n  $Output = array();\n  \n  \n  $DateTimeNow = strtotime($DateTimeNow);\n\n  \/\/----- ARE WE INTO A NEW DAY? -----\n  if ( intval((date('G', $DateTimeNow))) >= $DayChangeHour )\n  {\n    \/\/WE ARE INTO THE NEW DAY\n    \n  }\n  else\n  {\n    \/\/WE ARE STILL PART OF YESTERDAY (e.g. its 1am)\n    $DateTimeNow = strtotime('-1 day',$DateTimeNow);\n  }\n  \n  \/\/----- FILL THE ARRAY WITH THE DAY NAMES -----\n  $Output&#91;] = date($DayNameChar, $DateTimeNow);\n  while ($NumberOfPastDayNames--)\n  {\n    $DateTimeNow = strtotime('+1 day',$DateTimeNow);\n    $Output&#91;] = date($DayNameChar, $DateTimeNow);\n  }\n  \n  return($Output);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Get # day names from DateTime and into the past Get # day names from DateTime and into the future<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[249],"tags":[],"class_list":["post-2869","post","type-post","status-publish","format-standard","hentry","category-useful-code"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2869"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2869\/revisions"}],"predecessor-version":[{"id":2875,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2869\/revisions\/2875"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}