Get # day names from DateTime and into the past


//*************************************************
//*************************************************
//********** GET X DAY NAMES IN THE PAST **********
//*************************************************
//*************************************************
//$DayChangeHour
//  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)
//$DayNameChar
//  'D' = Mon through Sun, 'l' = 	Sunday through Saturday
//Returns an array:
//  [0] Todays day name
//  [1] Previous day name
//  [#] etc
/* Example usage
  $DayNames = GetXDayNamesInThePast($ServerTimeNow, 7, "D", 4);
  print_r($DayNames);
*/
function GetXDayNamesInThePast ($DateTimeNow, $NumberOfPastDayNames, $DayNameChar, $DayChangeHour)
{
  $Output = array();
  
  
  $DateTimeNow = strtotime($DateTimeNow);

  //----- ARE WE INTO A NEW DAY? -----
  if ( intval((date('G', $DateTimeNow))) >= $DayChangeHour )
  {
    //WE ARE INTO THE NEW DAY
    
  }
  else
  {
    //WE ARE STILL PART OF YESTERDAY (e.g. its 1am)
    $DateTimeNow = strtotime('-1 day',$DateTimeNow);
  }
  
  //----- FILL THE ARRAY WITH THE DAY NAMES -----
  $Output[] = date($DayNameChar, $DateTimeNow);
  while ($NumberOfPastDayNames--)
  {
    $DateTimeNow = strtotime('-1 day',$DateTimeNow);
    $Output[] = date($DayNameChar, $DateTimeNow);
  }
  
  return($Output);
}

Get # day names from DateTime and into the future


//***************************************************
//***************************************************
//********** GET X DAY NAMES IN THE FUTURE **********
//***************************************************
//***************************************************
//$DayChangeHour
//  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)
//$DayNameChar
//  'D' = Mon through Sun, 'l' = 	Sunday through Saturday
//Returns an array:
//  [0] Todays day name
//  [1] Next day name
//  [#] etc
/* Example usage
  $DayNames = GetXDayNamesInThePast($ServerTimeNow, 7, "D", 4);
  print_r($DayNames);
*/
function GetXDayNamesInTheFuture ($DateTimeNow, $NumberOfFutureDayNames, $DayNameChar, $DayChangeHour)
{
  $Output = array();
  
  
  $DateTimeNow = strtotime($DateTimeNow);

  //----- ARE WE INTO A NEW DAY? -----
  if ( intval((date('G', $DateTimeNow))) >= $DayChangeHour )
  {
    //WE ARE INTO THE NEW DAY
    
  }
  else
  {
    //WE ARE STILL PART OF YESTERDAY (e.g. its 1am)
    $DateTimeNow = strtotime('-1 day',$DateTimeNow);
  }
  
  //----- FILL THE ARRAY WITH THE DAY NAMES -----
  $Output[] = date($DayNameChar, $DateTimeNow);
  while ($NumberOfPastDayNames--)
  {
    $DateTimeNow = strtotime('+1 day',$DateTimeNow);
    $Output[] = date($DayNameChar, $DateTimeNow);
  }
  
  return($Output);
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *