just trying to create a variable where it outputs the exact current datetime and adding exactly one additional year. how do i add the days?
$expirationdate = date('Y-m-d H:i:s', .' + 1 year'));
Also, if a person manually modifies the date on their PC/Phone, will that time be the start of the current date on the variable?
尝试这个 :
$date= date('Y-m-d H:i:s',strtotime('+1 years'));
Try with below code:
$expirationdate = date('Y-m-d H:i:s', strtotime('+1 years'));
I hope it will help you.
You can achieve your result by using strtotime()
and date()
function of php
$expirationdate = date('Y-m-d H:i:s', strtotime('+ 1 year'));
print_r($expirationdate);
You can read more about the strtotime() and date()
I think the best way to work with dates and time in PHP is through the DateTime object. You can use modify
method to add or subtract days, years or whatever you want, like this:
$d = new DateTime(); //current date
$d->modify('+10 days');
$d->modify('+1 year');
echo $d->format('Y-m-d H:i:s');
Regarding your second question if a person modifies date on his computer it won't change anything because PHP runs on the server and takes date from it (not from the user machine).
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.