PHP Tutorial - PHP date_date_set() Function






Definition

The date_date_set() function sets a new date.

Syntax

PHP date_date_set() Function has the following syntax.

date_date_set(object,year,month,day);

Parameter

ParameterIs RequiredDescription
objectRequired.DateTime object returned by date_create()
yearRequired.Year of the date
monthRequired.Month of the date
dayRequired.Day of the date

Return

PHP date_date_set() Function returns a new DateTime object on success. FALSE on failure.





Example

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 code above generates the following result.