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");
?>

Run Example

Definition and Usage

date_date_set() function sets a new date.

Syntax

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

Technical Details

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