显示下个月的第10天

时间:2016-07-12 16:45:11

标签: php

我希望显示下个月的第10天。

这是我所拥有的显示下个月第一天的代码。我如何修改它以获得下个月的第10天。

if ($MyRow['daysbeforedue'] > 0) {
                /* Make a due date form trandate plus terms */
                $dateDue = date_create($MyRow['trandate']);
                date_add($dateDue, date_interval_create_from_date_string( ($MyRow['daysbeforedue'].' days')));
                $dateDue->modify( 'first day of this month' );
                $formatedDueDate =date_format($dateDue, 'm/d/Y');

            } 
            else { //More than 1 month
                /* Make a due date form trandate plus terms */
                $dateDue = date_create($MyRow['trandate']);
                date_add($dateDue, date_interval_create_from_date_string( ('1 month')));
                date_add($dateDue, date_interval_create_from_date_string( ($MyRow['dayinfollowingmonth'].' days')));
                $dateDue->modify( 'first day of this month' );
                $formatedDueDate = date_format($dateDue, 'm/d/Y');
                //$formatedDueDate = '';
            }

1 个答案:

答案 0 :(得分:2)

请参阅:DateTime::add

例如,

 $date = new DateTime('2000-01-01');      // First day of month.
 $date->add(new DateInterval('P10D'));    // Adding 10 days
 echo $date->format('m/d/Y');             // 1/11/2000