I need to add N months and M days to the current time() in PHP. My current solution is simple, but I was wondering can it be even simpler :)?
$my_time = strtotime("+6 days", strtotime("+1 month", time()));
I am also wondering if there is a chance to avoid weekends (Saturday and Sunday) in the target date?
Yes, you can simplify it to:
$my_time = strtotime("+6 days 1 month", time());
Or:
$my_time = strtotime("+6 days 1 month");
See this
Try this following Methods use strtotime() function add days months years
For Day add date('Ym-d', strtotime("+3 days")); For month add
date('Y-m-d', strtotime("+3 month"));
year add
date('Y-m-d', strtotime("+3 year"));
For day month year add
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
For subtract day month year
date('Y-m-d', strtotime("-1 days 1 month 1 year "));
just use ( + and - ) symbols
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.