English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
date_isodate_set() function sets ISO date
date_isodate_set()Function is DateTime::setISODate Alias. This function can be used to set ISO date. With ISO 8601 Set the date in a standard format, using the offset of the week and day as parameters instead of the month and day.
date_isodate_set($object, $year, $week, $day)
Serial Number | Parameters and Description |
---|---|
1 | object(Required) This is a DateTime object, you need to set the date for it. |
2 | year(Required) Year. |
3 | week(Required) Week. |
4 | day(Required) Calculate the offset of the day within the week starting from the first day of the week. |
Returns the modified DateTime object, this function will return a boolean valuefalse.
This function was originally introduced in PHP version5.2introduced in version 5.3.0 and is available in all higher versions.
The following examples demonstratedate_isodate_setUsage of the function-
<?php //Create Date $date = new DateTime(); //to set ISO date date_isodate_set($date, 2019, 03, 3); print("Date: " . date_format($date, "Y/m/d")); ?>Test to see‹/›
Output Result
Date: 2019/01/16
The following example creates a DateTime object and usesdate_isodate_set()The function modifies its date.-
<?php //Date String $date_string = "25-09-1999"; //Create a DateTime object $date_time_Obj = date_create($date_string); print("Original Date: " . date_format($date_time_Obj, "Y/m/d")); print("\n"); //Set Date $date = date_isodate_set($date_time_Obj, 2015, 4, 3 ); print("Modified Date: " . date_format($date, "Y/m/d")); ?>Test to see‹/›
Output Result
Original Date: 1999/09/25 Modified Date: 2015/01/21
If the day and week values you pass to this function are out of range, they will be added to the parent value-
<?php //Create Date $date = new DateTime(); //Set Date date_isodate_set($date, 2019, 15, 17); print("Date: " . date_format($date, "Y/m/d")); ?>Test to see‹/›
This will produce the following output-
Date: 2019/04/24
<?php $dateSrc = '2005-04-19 12:50 GMT'; $dateTime = date_create($dateSrc);; #Now use date_isodate_set() to set the new date; date_isodate_set( $dateTime, 2000, 12, 12); echo "The new formatted date is " . $dateTime->format("Y-m-d\TH:i:s\Z"); echo "<br>"; #Use the second function. $dateTime = new DateTime($dateSrc); $dateTime->setISODate( 1999, 10, 12); echo "The new formatted date is " . $dateTime->format("Y-m-d\TH:i:s\Z"); ?>Test to see‹/›
This will produce the following output-
The new formatted date is 2000-03-31T12:50:00Z The new formatted date is 1999-03-19T12:50:00Z