PHP - Function date_time_set()


Advertisements


Syntax

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

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

Definition and Usage

These functions set the time in the passed object.

The above two functions are equivalent and any of the functions can be used as shown below in the example.

Parameters

Sr.No Parameter & Description
1

object(Required)

DateTime object

2

hour(Required)

Hour to be set

3

minute(Required)

Minute to be set

4

second(Optional)

Second to be set

Return Value

It returns NULL on success or FALSE on failure.

Example

Following is the usage of this function −

Live Demo
<?php
   $dateSrc = '2007-04-19 12:50 GMT';
   $dateTime = date_create( $dateSrc);;
   $retval = date_time_set( $dateTime, 20, 40, 10);
   
   echo 'DateTime::format(): '.$dateTime->format('Y:M:D:H:i:s');
   echo "\n";

   # Using second function.
   $dateTime = new DateTime($dateSrc);
   $retval = $dateTime->setTime(20, 56,6);
   
   echo 'DateTime::format(): '.$dateTime->format('Y:M:D:H:i:s');
?> 

This will produce the following result −

DateTime::format(): 2007:Apr:Thu:20:40:10
DateTime::format(): 2007:Apr:Thu:20:56:06

php_function_reference.htm

Advertisements