I want to add a number of days to the current date: For example, I want to get the date that comes after 180 days from the current date. I am trying to build a subscription system where the user package will expire in 30 days or 60 days or 180 days, so how do I get the expiring date?
Hope my question is clear.
You can use strtotime(time, now)
which returns a Unix timestamp. Then you can use date('Y-m-d', $timestamp)
to formate the timestamp. strtotime
supports US English date format.
Try the example below.
echo date('Y-m-d', strtotime("+180 days"));
This will calculate from the current date, but if you want to start from a specific date, you can use the second argument.
$from_date = strtotime("2022-10-25");
echo date('Y-m-d', strtotime("+180 days", $from_date));