setDate(Year, month, day)
Here are some examples to set the date.
date_default_timezone_set('America/Chicago');
$today = new DateTime;
echo $today->format('Y-m-d ');
echo "<br>";
$today->setDate(13,11,20);
echo $today->format('Y-m-d');
The output is here
2025-10-17
0013-11-20
IN above code we can change the setDate function parameters and check the output. We can change to higher values for year and month , the function will adjust it to the next values and display the correct dates. Here are the changes ( only )
$today->setDate(13,14,31);
The output is here2025-10-17
0014-03-03
$date = date_create();
date_date_set($date, 2019, 8, 13);
echo date_format($date, 'Y-m-d');
Output is here 2019-08-13
PHP Date FunctionssetTime() : Set time for date object
Timestamp in PHP Displaying calendar for selection of date by user
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.