0

I've done a function for incremnting dates

here is the following:

function periode($var, $i3, $i2)
    {
        if($var=='52')
        {
            return "+ ".$i3." week";
        }
        if($var=='26')
        {   
            return "+ ".($i3+2+$i3)." week";
        }
        if($var=='12')
        {
            return "+".$i3." month";
        }
        if($var=='6')
        { 
            return "+ ".($i3+$i2)." month";
        }
        if($var=='4')
        {  
            return "+ ".($i3+2*$i2)." month";
        }
        if($var=='2')
        {

            return "+ ".($i3+5*$i2)." month";
        }
        if($var=='1')
        {
            return "+ ".($i2)." year";
        }


    }

the trouble is that when I use that function like that:

if($pay_periodicity==26){$i3=0;}elseif($pay_periodicity==4){$i3=0;}elseif($pay_periodicity==6){$i3=0;}else{$i3=0;}; $i2=0;
 $montant_echeance = round($montant_du / $nombre_echeances, 2);
 $reste=$montant_du ;
 while($i2 <= $nombre_echeances)
 {
        echo periode($pay_periodicity,$i3,$i2);
        if ($i2 == $nombre_echeances)
        {
                $montant_echeance = $reste;
                $reste = 0;
        } 

     $date    = date("d-m-Y",strtotime((($debut)."".periode($pay_periodicity,$i3,$i2)."")));  
     $chaine .= "<tr>
     <td>$montant_du</td>
      <td>".$date."</td>
     <td>$montant_echeance</td>
     <td>$reste</td></tr>";
           $reste = $reste-$montant_echeance;
     $i2++;
     ++$i3;
        }
$chaine .="</table>";
print "$chaine";


    }

after the 25th $i2, it display date like that:

01-01-1970

I really do not understand why we can not increment more than 25 years.

Any help or advice will be much appreciated.

Kind regards.

SP.

Stanislas Piotrowski
  • 2,595
  • 10
  • 40
  • 59

1 Answers1

3

You are experiencing an overflow-problem. The highest date possible to store in a 32-bit variable occurs at 2038-01-19

http://en.wikipedia.org/wiki/Year_2038_problem explains the problem.

Edit:
One solution is to upgrade to a 64bit version of PHP if the underlaying architecture is 64 bit as well.

From how to have 64 bit integer on PHP?:
Native 64-bit integers require 64-bit hardware AND the 64-bit version of PHP.

On 32-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
2147483647

On 64-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
9223372036854775807
Community
  • 1
  • 1
mariusnn
  • 1,847
  • 18
  • 30