PHP makes it easy to work with dates and times using the date() function and DateTime class. You can format dates, calculate differences, and handle timezones. Always store dates in UTC and convert to local time only for display.
Date and Time
// Current timestamp
time(); // Unix timestamp (seconds)
date("Y-m-d H:i:s"); // 2024-01-15 10:30:00
date("d/m/Y"); // 15/01/2024
date("l, F j, Y"); // Monday, January 15, 2024
date("D, d M Y H:i:s"); // Mon, 15 Jan 2024 10:30:00
// Modify dates
strtotime("+7 days"); // timestamp 7 days from now
strtotime("next Monday");
strtotime("2024-12-25"); // parse date string
// DateTime class (recommended)
$dt = new DateTime();
$dt->modify("+1 month");
echo $dt->format("Y-m-d");
// Date difference
$d1 = new DateTime("2024-01-01");
$d2 = new DateTime("2024-12-31");
$diff = $d1->diff($d2);
echo $diff->days; // 365