date_sunset
date_timezone_get
Date/Time Functions
PHP Manual

# date_time_set

(PHP 5 >= 5.2.0)

date_time_set — Sets the time

### Description

void date_time_set ( DateTime `$object` , int `$hour` , int `$minute` [, int `$second` ] )
void DateTime::setTime ( int `$hour` , int `$minute` [, int `$second` ] )

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

### Parameters

`object`

  Procedural style only: A DateTime object returned by date_create()

`hour`

  Hour of the time.

`minute`

  Minute of the time.

`second`

  Second of the time.

### Return Values

Returns `NULL` on success or `FALSE` on failure.

### Examples

Example #1 Changing the time of a DateTime object

`<?php
date_default_timezone_set('Europe/London');
$datetime = new DateTime('2008-08-03 12:35:23');
echo $datetime->format('Y-m-d H:i:s') . "\n";
$datetime->setTime(14, 55, 24);
echo $datetime->format('Y-m-d H:i:s') . "\n";
// Warning: Does not increment the hour!
// This is because the hour has been set (14) - see date_modify()
$datetime->setTime($datetime->format('H'), $datetime->format('n') + 6);
echo $datetime->format('Y-m-d H:i:s') . "\n";
// *Does* increment the day, because the day has not been set
$datetime->setTime($datetime->format('H') + 12, $datetime->format('n'));
echo $datetime->format('Y-m-d H:i:s') . "\n";
?>`

The above example will output:

    2008-08-03 12:35:23
    2008-08-03 14:55:24
    2008-08-03 14:14:00
    2008-08-04 02:08:00

### See Also

- date_date_set()

date_sunset
date_timezone_get
Date/Time Functions
PHP Manual