dinesh
dinesh

Reputation: 87

i am trying to add a month to a date in php, the date is picked via datepicker YYY-MM-DD format

I am trying to add months to a date

for ($i=0;$i<$months;$i++)
{
    $newdate = strtotime ( "+1 month", strtotime ( $date ) );
    $newdate = date ( 'Y-m-j' , $newdate );
}

how to get the $i inside the function?

Upvotes: 0

Views: 35

Answers (1)

Richi Zee
Richi Zee

Reputation: 374

that is one possible solution

for ($i=1;$i<=$months;$i++)
{
    $newdate = strtotime ( "+".$i." month", strtotime ( $date ) );
    $newdate = date ( 'Y-m-j' , $newdate );
}

Upvotes: 1

Related Questions