DateTime::setTime

date_time_set

Sets the time

&reftitle.description;

&style.oop;

public `DateTime` `DateTime::setTime` `int` `hour` `int` `minute` `int` `second` 0

&style.procedural;

`DateTime` `date_time_set` `DateTime` `object` `int` `hour` `int` `minute` `int` `second` 0

Resets the current time of the DateTime object to a different time.

&reftitle.parameters;
&date.datetime.description.modified;

`hour`

- Hour of the time.

`minute`

- Minute of the time.

`second`

- Second of the time.

&reftitle.returnvalues;

&date.datetime.return.modifiedobjectorfalseforfailure;

&reftitle.changelog;

&Version; | &Description;
&date.datetime.retval.changelog;

&reftitle.examples;

### `DateTime::setTime` example

&style.oop;

    <?php
    $date = new DateTime('2001-01-01');

    $date->setTime(14, 55);
    echo $date->format('Y-m-d H:i:s') . "\n";

    $date->setTime(14, 55, 24);
    echo $date->format('Y-m-d H:i:s') . "\n";
    ?>

&style.procedural;

    <?php
    $date = date_create('2001-01-01');

    date_time_set($date, 14, 55);
    echo date_format($date, 'Y-m-d H:i:s') . "\n";

    date_time_set($date, 14, 55, 24);
    echo date_format($date, 'Y-m-d H:i:s') . "\n";
    ?>

&examples.outputs.similar;

    2000-01-01 14:55:00
    2000-01-01 14:55:24

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

    <?php
    $date = new DateTime('2001-01-01');

    $date->setTime(14, 55, 24);
    echo $date->format('Y-m-d H:i:s') . "\n";

    $date->setTime(14, 55, 65);
    echo $date->format('Y-m-d H:i:s') . "\n";

    $date->setTime(14, 65, 24);
    echo $date->format('Y-m-d H:i:s') . "\n";

    $date->setTime(25, 55, 24);
    echo $date->format('Y-m-d H:i:s') . "\n";
    ?>

&example.outputs;

    2001-01-01 14:55:24
    2001-01-01 14:56:05
    2001-01-01 15:05:24
    2001-01-02 01:55:24

&reftitle.seealso;

- `DateTime::setDate`
- `DateTime::setISODate`