Return a new DateTime object, set the date to a specified value, and then format it.
| <?php $date=date_create(); date_date_set($date,2020,10,30); echo date_format($date,“Y/m/d”); ?> |
The date_date_set() function updates the date of a DateTime object.
| date_date_set(object, year, month, day) |
|
Parameter |
Description |
|
object |
Required. Specifies a DateTime object created by date_create(). |
|
year |
Required. Specifies the year of the date. |
|
month |
Required. Specifies the month of the date. |
|
day |
Required. Specifies the day of the date. |
|
Return Value: |
Returns the updated DateTime object on success; FALSE on failure. |
|
PHP Version: |
5.2+ |
|
PHP Changelog: |
In PHP 5.3, the return value was changed from NULL to DateTime on success. |