The date_date_set() function is an inbuilt function in PHP which is used to set a new Date. This function has four parameters $object, $year, $month and $day and returns DateTime object on success or false on failure. The date_date_set() function is an alias of DateTime::setDate() function.
Syntax:
date_date_set( $object, $year, $month, $day )
Parameters: This function accepts four parameters as mentioned above and described below:
- $object: It is a mandatory parameter which is used to specify the DateTime object which is returned by the date_create() function.
- $year: It is a mandatory parameter which is used to specify the year of the date.
- $month: It is a mandatory parameter which is used to specify the month of the date.
- $day: It is a mandatory parameter which is used to specify the day of the date.
Return Value:This function returns a new DateTime object on success or FALSE on failure.
Below programs illustrate the date_date_set() function in PHP.
Program 1: Procedural style to print DateTime.
<?php // Date_create() returns a new DateTime object. $date = date_create(); // date_date_set() function date_date_set($date, 2018, 8, 31); // Print the date in a format echo date_format($date, "Y/m/d"); ?> |
2018/08/31
Program 2: Object oriented style to print DateTime.
<?php // Declare DateTime object. $date = new DateTime(); // date_date_set() function $date->setDate(2018, 8, 31); // Print the date in a format echo $date->format('Y/m/d'); ?> |
2018/08/31
Related Articles:
Reference: http://php.net/manual/en/function.date-date-set.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
- PHP | is_numeric() Function
- PHP | Imagick adaptiveSharpenImage() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

