DateTimeImmutable::setISODate

Sets the ISO date

&reftitle.description; public `DateTimeImmutable` `DateTimeImmutable::setISODate` `int` `year` `int` `week` `int` `dayOfWeek` 1

Returns a new DateTimeImmutable object with the date set according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.

&reftitle.parameters;

`year`

- Year of the date.

`week`

- Week of the date.

`dayOfWeek`

- Offset from the first day of the week.

&reftitle.returnvalues;

&date.datetimeimmutable.return.modifiedobject;

&reftitle.examples;

### `DateTimeImmutable::setISODate` example

&style.oop;

    <?php
    $date = new DateTimeImmutable();

    $date->setISODate(2008, 2);
    echo $date->format('Y-m-d') . "\n";

    $date->setISODate(2008, 2, 7);
    echo $date->format('Y-m-d') . "\n";
    ?>

&style.procedural;

    <?php
    $date = date_create();

    date_isodate_set($date, 2008, 2);
    echo date_format($date, 'Y-m-d') . "\n";

    date_isodate_set($date, 2008, 2, 7);
    echo date_format($date, 'Y-m-d') . "\n";
    ?>

&examples.outputs;

    2008-01-07
    2008-01-13

### Values exceeding ranges are added to their parent values

    <?php
    $date = new DateTimeImmutable();

    $newDate = $date->setISODate(2008, 2, 7);
    echo $newDate->format('Y-m-d') . "\n";

    $newDate = $date->setISODate(2008, 2, 8);
    echo $newDate->format('Y-m-d') . "\n";

    $newDate = $date->setISODate(2008, 53, 7);
    echo $newDate->format('Y-m-d') . "\n";
    ?>

&example.outputs;

    2008-01-13
    2008-01-14
    2009-01-04

### Finding the month a week is in

    <?php
    $date = new DateTimeImmutable();
    $newDate = $date->setISODate(2008, 14);
    echo $newDate->format('n');
    ?>

&examples.outputs;

    3

&reftitle.seealso;

- `DateTimeImmutable::setDate`
- `DateTimeImmutable::setTime`