PHP Dates and Times
date formats a timestamp; strtotime parses text; the DateTime class does arithmetic. Use a fixed date here so the output is predictable.
ExamplePHP
<?php
date_default_timezone_set("UTC");
$ts = mktime(12, 30, 0, 11, 4, 2026);
echo date("Y-m-d H:i:s", $ts), "\n";
echo date("l, F jS, Y", $ts), "\n";
$d = new DateTime("2026-11-04");
$d->modify("+30 days");
echo $d->format("Y-m-d"), "\n";
$a = new DateTime("2026-01-01");
$b = new DateTime("2026-12-25");
$diff = $a->diff($b);
echo $diff->days, " days\n";
echo date("D", strtotime("2026-11-04")), "\n";
var_dump(checkdate(2, 30, 2026));Output
2026-11-04 12:30:00 Wednesday, November 4th, 2026 2026-12-04 358 days Wed bool(false)
Quick check
Which class does date arithmetic like adding 30 days?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.