Kadir Çetintaş
Kadir Çetintaş

Reputation: 207

Php find time intervals between two timestamp

I have three variable.

First: Start date stamp and its string value(04.10.2015 13:30:00)
Second: End date stamp and its string value(04.10.2015 18:30:00)
Interval: Time interval minutes and its integer value(20)

I want to find all times between this timestamps each 20 minutes. Like:

04.10.2015 13:30:00
04.10.2015 13:50:00
04.10.2015 14:10:00
04.10.2015 14:30:00
04.10.2015 14:50:00
04.10.2015 15:10:00
04.10.2015 15:30:00
04.10.2015 15:50:00
04.10.2015 17:10:00
04.10.2015 17:30:00
04.10.2015 17:50:00
04.10.2015 18:10:00
04.10.2015 18:30:00

How can i do this,

Thanks

Upvotes: 1

Views: 315

Answers (2)

lakshman
lakshman

Reputation: 656

Use

for($i = strtotime('04-10-2015 13:30:00'); $i <= strtotime('04-10-2015 18:30:00'); $i += 1200) {
    echo date('d m Y H:i:s', $i) . '<br />';
}

1200 = 20 Mins * 60 Seconds

Upvotes: 4

Gorakh Yadav
Gorakh Yadav

Reputation: 302

$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

Upvotes: -1

Related Questions