Home >>PHP Date Time Functions >PHP date_time_set() Function

PHP date_time_set() Function

PHP date_time_set() Function

PHP date_time_set() function is used to sets the time value. It sets the current time of the DateTime object to a different time. It accepts five different parameters. It returns the DateTime object on success or False on failure.

Syntax:

date_time_set(object, hour, minute, second, microseconds);

Parameter Values

Parameter Description
object This is a required parameter. This parameter defines a DateTime object returned by date_create().
hour This is a required parameter. This parameter defines the hour of the time.
minute This is a required parameter. This parameter defines the minute of the time.
second This is an optional parameter. This parameter defines the second of the time.
microseconds This is an optional parameter. This parameter defines the microsecond of the time.

Here is an example of date_time_set() function in PHP:

<html>
<body>
<?php
$date=date_create();
date_time_set($date,05,30);
echo date_format($date,"d-m-Y H:i:s");
?>
</body>
</html>
Output:
31-01-2020 05:30:00

Example 2

<html>
<body>
<?php
$date=date_create("10-06-2020");
date_time_set($date,04,05,33);
echo date_format($date,"d-M-Y H:i:s");
?>
</body>
</html>
Output:
10-Jun-2020 04:05:33

No Sidebar ads