PHP offre potenti funzioni per gestire date e orari.
Funzione date()
echo date("Y-m-d"); // 2024-01-15
echo date("d/m/Y"); // 15/01/2024
echo date("H:i:s"); // 14:30:00
echo date("l, d F Y"); // Monday, 15 January 2024Timestamp
$now = time(); // Timestamp corrente
$future = strtotime("+1 week");
$custom = strtotime("2024-12-25");
echo date("Y-m-d", $future);DateTime class
$date = new DateTime();
$date = new DateTime("2024-06-15");
$date->modify("+1 month");
echo $date->format("Y-m-d");
// Differenza tra date
$diff = $date1->diff($date2);
echo $diff->days . " giorni";