Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Absolute strings echo date('Y-m-d', strtotime('2024-12-25')); // 2024-12-25 echo date('Y-m-d', strtotime('December 25, 2024')); // 2024-12-25 // Relative strings echo date('Y-m-d', strtotime('+7 days')); // 7 days from now echo date('Y-m-d', strtotime('-1 month')); // 1 month ago echo date('Y-m-d', strtotime('next Monday')); // upcoming Monday echo date('Y-m-d', strtotime('last Sunday')); // previous Sunday echo date('Y-m-d', strtotime('first day of next month')); echo date('Y-m-d', strtotime('last day of this month')); // Relative to a base timestamp (second argument) $base = strtotime('2024-01-15'); echo date('Y-m-d', strtotime('+1 month', $base)); // 2024-02-15 // Validate $ts = strtotime('not a date'); if ($ts === false) { echo 'Invalid date string'; }
Result
Open