To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:

a. $days = new DateInterval('P90D');
$due_date = date();

$due_date = $due_date->add($days);

b. $days = new DateInterval('P90D');
$due_date = new DateTime();

$due_date = $due_date->add($days);

c. $days = new DateInterval('P90D');
$due_date = date();

$due_date = $due_date + $days;

d. $days = new DateInterval('P90D');
$due_date = new DateTime();

$due_date = $due_date + $days;
b. $days = new DateInterval('P90D');
$due_date = new DateTime();

$current_date = new DateTime();

$due_days_diff = $current_date->diff($due_date);

if ($current_date > $due_date) {

$overdue_message = $due_days_diff->format(

'%y years, %m months, and %d days overdue.');

}
14. (Refer to code example 10-1) If $due_date contains a DateTime object, $due_date_diff will contain

a. a TimeStamp object
b. a DateTime object
c. a DateInterval object
d. a TimeInterval object

Respuesta :

If $due_date contains a DateTime object, $due_date_diff will contain  

c. a DateInterval object

Explanation:

  • The DateInterval class ¶  represents a date interval.
  • A date interval stores either a fixed amount of time (in years, months, days, hours etc) or a relative time string in the format that DateTime's constructor supports.
  • The diff method is just as easy to use, but provides an extra piece of information: total days. This is important because when using the DateTime object to find a difference, we have a source and destination date, and therefore we can reduce the units of time into larger denominations. However, having the total number of days in between is a valuable piece of information.
  • The PHP DateTime class has three methods that work with a DateInterval object:
  1. add
  2. sub
  3. diff

Properties

  • y  :Number of years.
  • m  :Number of months.
  • d  :Number of days.
  • h  :Number of hours.
  • i  :Number of minutes.
  • s  :Number of seconds.