Return all dates or time between two dates in an array

  • 5 years-11 months

    Return all dates or time between two dates in an array

    • Category : php
    • Viewed : 54 times
    • Posted On :
    • Posted by : Vikas

    Return all dates or time between two dates in an array

    print_r(createDateTimeRangeArray('2007-01-15 11:15:00', '2007-01-20 18:15:00','  1 day','d/m/Y h:i:s A'));
    
    
    function createDateTimeRangeArray($start,$end,$step = '  30 minutes',$output_format = 'H:i') {
      $range = array();
     if (is_string($start) === true) $start = strtotime($start);
     if (is_string($end) === true ) $end = strtotime($end);
      if ($start > $end) return createDateTimeRangeArray($end, $start);
      do {
        //$range[] = date('Y-m-d', $start);
       $range[] = date($output_format, $start);
        $start = strtotime($step, $start);
      }
     while($start < $end);
      return $range;
    } 

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.