在PHP中动态添加x天到日期(Dynamically adding x number of days to a date in PHP)
我有一个场景,我必须添加x数字,如果天数包含日期的变量。 这个x将是动态的,无法猜到。
关于如何实现这一点的任何建议?
$ticket_created_on_date_time = '2016-08-31 09:55:01' $in_between_days = 2;I have a scenario where I have to add x number if days to a variable containing date. This x will be dynamic and cannot be guessed.
Any suggestions on how I can implement this?
$ticket_created_on_date_time = '2016-08-31 09:55:01' $in_between_days = 2;最满意答案
您可以使用数学和strtotime函数来获取过去/未来的日期。 就像是:
strtotime($ticket_created_on_date_time) + (86400 * $in_between_days)(86400是几秒钟内)....或
strtotime($ticket_created_on_date_time . '+ ' . $in_between_days . ' days')演示: https : //eval.in/634187
You can use math and the strtotime function to get a date in the past/future. Something like:
strtotime($ticket_created_on_date_time) + (86400 * $in_between_days)(86400 is one day in seconds) ....or
strtotime($ticket_created_on_date_time . '+ ' . $in_between_days . ' days')Demo: https://eval.in/634187
更多推荐
发布评论