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

date_time_set() function in PHP


The date_time_set() function sets the time. It returns a DateTime object on success. FALSE on failure.

Syntax

date_time_set(obj, hour, minute, second)

Parameters

  • obj − DateTime object

  • hour − Hour of the time to set

  • minute − Minute of the time to set

  • second − Second of the time to set

Return

The date_time_set() function returns a DateTime object on success. FALSE on failure.

Example

The following is an example −

<?php
   $dt = date_create("2018-09-05");
   date_time_set($dt,8,15);
   echo date_format($dt,"Y-m-d H:i:s");
?>

Output

The following is the output −

2018-09-05 08:15:00

Example

Let us see another example −

<?php
   $dt = date_create("2017-08-08");
   date_time_set($dt,13,24);
   echo date_format($dt,"Y-m-d H:i:s");
?>

Output

The following is the output −

2017-08-08 13:24:00