Return a new DateTime object, set a new date, and then format the date:
<?php$date=date_create();date_date_set($date,2020,10,30);echo date_format($date,"Y/m/d");?>The date_date_set() function sets a new date.
date_date_set( object,year,month,day);
parameter | describe |
---|---|
object | Required. Specifies a DateTime object returned by date_create(). |
year | Required. The year in the specified date. |
month | Required. The month in the specified date. |
day | Required. The day of the specified date. |
Return value: | Returns a new DateTime object if successful, or FALSE if failed. |
---|---|
PHP version: | 5.2+ |
Update log: | Starting from PHP 5.3+, if successful, the return value changes from NULL to DateTime. |