PHP date_date_set() Function

Example

Returns a new DateTime object, sets a new date, and then formats the date:

<?php
$date=date_create();
date_date_set($date,2020,10,15);
echo date_format($date,"Y/m/d");
?>

Running Instance

Definition and Usage

The date_date_set() function sets a new date.

Syntax

date_date_set(object,year,month,day);
parameters description
object Required. Specifies by date_create() The returned DateTime object.
year Required. Specifies the year in the date.
month Required. Specifies the month in the date.
day Required. Specifies the day in the date.

Technical Details

Return Value: If successful, it returns a new DateTime object; if not, it returns FALSE.
PHP Version: 5.2+
Update Log: Starting from PHP 5.3+, if successful, the return value changes from NULL to DateTime.