We can assign new date to any date object by using setDate function. Using this we can change the date object.
setDate(Year, month, day)
Here are some examples to set the date.
$today = new DateTime;
echo $today->format('Y-m-d ');
echo "<br>";
echo $today->format('Y-m-d');
The output is here
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 )
The output is here

Procedural style

$date = date_create();
date_date_set($date, 2019, 8, 13);
echo date_format($date, 'Y-m-d');
Output is here
PHP Date Functions setTime() : Set time for date object Timestamp in PHP Displaying calendar for selection of date by user
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer