简体   繁体   中英

how to add days in current date

echo "No of days:";
$var1 = file_get_contents('path to file');
echo $var1;
$var2= "-".$var1." days";  // var2= -2 days

$today = date("M d, Y");
echo $today;
$NewDate=Date(strtotime($var2));
echo date('M d, Y', $NewDate);

Error:Warning: date() expects parameter 2 to be long,

尝试这个:

$var2= $var1." days ago"; 
$var = file_get_contents('path to file');
echo date('M d Y',strtotime("-$var days"));

Why not do it like this:

    $date = new DateTime(date("M d, Y"));
    $todayPlusTwoDays = $date->add(new DateInterval('P2D'));

If $var1 holds the amount of days to add, simply:

    $todayPlusTwoDays = $date->add(new DateInterval('P'. $var1 .'D'));

From me

Remove this

$today = date("M d, Y");
echo $today;

You are not using it anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM