-1

I am getting date time from a form in the format

Date 1: 2019-01-25 08:30:00
Date 2: 2019-01-26 04:30:00

I need the output in 1 hour difference

2019-01-25 08:30 AM
2019-01-25 09:30 AM
2019-01-25 10:30 AM
2019-01-25 11:30 AM
2019-01-25 12:30 PM
2019-01-25 01:30 PM
2019-01-25 02:30 PM
2019-01-25 03:30 PM
2019-01-25 04:30 PM
2019-01-25 05:30 PM
2019-01-25 06:30 PM
2019-01-25 07:30 PM
2019-01-25 08:30 PM
2019-01-25 09:30 PM
2019-01-25 10:30 PM
2019-01-25 11:30 PM
2019-01-26 12:30 AM
2019-01-26 01:30 AM
2019-01-26 02:30 AM
2019-01-26 03:30 AM
2019-01-26 04:30 AM

How to do with php??

  • 1
    Possible duplicate of [PHP: Return all dates between two dates in an array](https://stackoverflow.com/questions/4312439/php-return-all-dates-between-two-dates-in-an-array) – Nick Jan 27 '19 at 12:06
  • Use the code from the duplicate, but change the DateInterval to `PT1H` (add one hour). – Nick Jan 27 '19 at 12:07
  • Hi @NImishaLinu. It looks like you are a new contributor. So, please take a look at https://stackoverflow.com/help/how-to-ask. I have never understood why some people just keep downvoting even for a new contributor. This might hold them back from asking the question in future. – Saroj Shrestha Jan 27 '19 at 12:40
  • @SarojShrestha Thanks a lot. I will take care in future. – NImisha Linu Jan 27 '19 at 13:54

1 Answers1

1

Is this what you are looking?

   $date1 = "2019-01-25 08:30:00";
   $date2 = "2019-01-26 04:30:00";

    while(strtotime($date1)<strtotime($date2)){
      $date1 = date('Y-m-d H:i:s',strtotime('+1 hour',strtotime($date1)));
      echo date("Y-m-d H:i: a",strtotime($date1));
      echo "</br>";
    }
Saroj Shrestha
  • 2,696
  • 4
  • 21
  • 45