Computer >> Computer tutorials >  >> Programming >> PHP

date_isodate_set() function in PHP


The date_isodate_set() function sets the ISO date. It returns NULL on success or FALSE on failure.

Syntax

date_isodate_set(object, year, week, day)

Parameters

  • object − DateTime object

  • year − Year of the date

  • week − Week of the date

  • day − Day of the date

Return

The date_isodate_set() function returns NULL on success or FALSE on failure.

Example

The following is an example −

<?php
   $dateSrc = '2018-10-11 11:15 GMT'; 
   $dateTime = date_create( $dateSrc);; 
   # Now set a new date using date_isodate_set(); 
   date_isodate_set( $dateTime, 2000, 12, 12); 
   echo "New Formatted date = ". $dateTime->format("Y-m-d\TH:i:s\Z"); 
   echo "<br />"; 
   
   # Using second function. 
   $dateTime = new DateTime($dateSrc); 
   $dateTime->setISODate( 1999, 10, 12); 
   echo "New Formatted date is ". 
   $dateTime->format("Y-m-d\TH:i:s\Z");
?>

Output

New Formatted date = 2000-03-31T11:15:00Z
New Formatted date is 1999-03-19T11:15:00Z

Let us see another example −

Example

<?php
   $d = date_create(); date_isodate_set($d,2017,9); echo date_format($d,"Y-m-d");
?>

Output

2017-02-27