Suvimo
Suvimo

Reputation: 250

Add variable days to specific date

I have the following script to do some date operation:

    function indate($leavedate){
    if($leavedate){
    $enddate=$leavedate[0]['LoppumisPvm'];//This prints 23 Apr
    $endday=date('d',strtotime($enddate));//this prints 23
    $endmonth=date('M',strtotime($enddate));// This prints Apr

    $additional_days=$endday-15;// This prints 8
    $end = strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days");
    echo $end;

I am trying to get that the variable $end That will add the number of additional days to a specific date (there given 15 Jan).. It prints 1358179200 instead..

Upvotes: 1

Views: 2182

Answers (2)

Rolando Isidoro
Rolando Isidoro

Reputation: 5114

You have a mix-up with an additional strtotime call and some bad positioned parenthesis. Change your code to:

$end = date("d M", strtotime("15 Jan + {$additional_days} days"));

Upvotes: 1

tvirelli
tvirelli

Reputation: 464

You need to change:

$end = strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days");

To be:

$end = date("d M",strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days"));

Upvotes: 0

Related Questions