barakuda28
barakuda28

Reputation: 2902

PHP: Dividing timeframe into 3 equal parts

Please take a look at the following code:

$parts_count = 3;
$diff = strtotime('2013-11-30 00:00:00') - time();
$diff = $diff / $parts_count;

for ($i = 0; $i < $parts_count; $i++) {
    echo date('Y-m-d H:m:s', time() + $diff * ($i + 1) );
}

I am trying to divide the difference between the current time and a deadline (2013-11-30 00:00:00) into 3 equal parts.

The result I get is more than interesting though. It is:

2013-11-16 23:11:36
2013-11-23 11:11:48
2013-11-30 00:11:00

As you see, the latest deadline is 11 minutes past the original deadline, which is very weird. Do you have an idea why this happens?

Upvotes: 0

Views: 267

Answers (1)

Alexander
Alexander

Reputation: 809

Misspelling in format, should be:

echo date('Y-m-d H:i:s', time() + $diff * ($i + 1) );

Upvotes: 5

Related Questions