I'm trying to make a script which penalizes a user daily after a time stamp. For the first day, it will penalize 1 point, second day 2 points, third 4 points, fourth 8 point, 16, 32, 64 and so on.
How would I go about auto generating a strtotime and the multiplications?
I really don't even know what i'm looking for is called at this point which makes searching hard, sorry if this has been posted.
Let's suppose, that $timestamp1 is the first day timestamp and the $timestamp2 is now timestamp. Then:
$difference = abs(strtotime($timestamp2)-strtotime($timestamp1));
$days = floor($difference / (60*60*24));
$penalty = pow(2,$days);
echo "{$days} left, so your penalty is: {$penalty}";
Sample results:
0 left, so your penalty is: 1
1 left, so your penalty is: 2
2 left, so your penalty is: 4
3 left, so your penalty is: 8
4 left, so your penalty is: 16
5 left, so your penalty is: 32
6 left, so your penalty is: 64
...
Try this
$initial_date = '2012-10-20';
$initial_datetime = new DateTime($initial_date);
$today_datetime = new DateTime();
$days_passed = $initial_datetime->diff($today_datetime)->format('%a');
$penalty = pow(2, ($days_passed-1));
echo $penalty;