Home >>PHP Date Time Functions >PHP date_date_set() Function

PHP date_date_set() Function

PHP date_date_set() Function

PHP date_date_set() function is used to set a new date also with a desired format of the date. It returns a datetime object as output.

Syntax:

date_date_set($object, $year, $month, $day);

Parameter Values

Parameter Description
object This is a required parameter. This parameter defines a DateTime object returned by date_create().
year This is a required parameter. This parameter defines the year of the date.
month This is a required parameter. This parameter defines the month of the date.
day This is a required parameter. This parameter defines the day of the date.

Here is an example of date_date_set() function in PHP:

<html>
<body>

<?php

$date=date_create("31-01-2020");
date_date_set($date,2020,02,14);
echo date_format($date,"d-M-Y");

?>

</body>
</html>
Output:
14-Feb-2020

Here is an example of date_date_set() function in PHP:

<html>
<body>

<?php

$date=date_create();   // current date will be passed
date_date_set($date,2050,01,01);
echo date_format($date,"j-M-Y (l)");

?>

</body>
</html>
Output:
1-Jan-2050 (Saturday)

No Sidebar ads