简体   繁体   中英

How to add days in current days dynamically in php

Currently i am working on creating ecommerce website in that on order return section user can only return goods for particular time from the time product was delivered.(Ex. if product is deliver on 10-7-2018 and return day vale in database is 10 than after 20-7-2018 the button of return should hide automatically.

$date1 = date("Y-m-d"); //Current Date
$date3 = $return_days['value']; //Day count value
//echo $date3.'<br>'; //it will print day count value                                           
$date2 = date("Y-m-d", strtotime($num['updated_date'] .'+'.$date3)); // i am adding $date3 and $num['updated_date'] value 

if $num['updated_date'] value is 10-7-2018 and $date3 value is 10 than output of $date2 should 20-7-2018 but my code is not giving desired output.

If any body know solution than please help.

You can use DateTime() object and add days using modify() method like below:

$daysForReturn = 10;

$date = new \DateTime();
$date->modify("+$daysForReturn day");
echo $date->format('Y-m-d'); // Output: 2018-08-24

You are on the right track, try this code below:

$date1 = date("Y-m-d"); //Current Date
$daysCount = $return_days['value']; //Day count value
$returnDate = date("Y-m-d", strtotime($num['updated_date'] .'+'.$daysCount.' days'));
echo $returnDate;

I think the following code works :

$Date = "2018-08-14"; // your delivery date
$days = "10"; /// extended days
echo date('Y-m-d', strtotime($Date. ' + '.$days.' days')); /// result

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