Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

date_time_set()

Example

Set the time for a DateTime object.

<?php
$date=date_create(“2013-05-01”);
date_time_set($date,13,24);
echo date_format($date,“Y-m-d H:i:s”);
?>

Definition and Usage

The date_time_set() function sets the time for a DateTime object.

Syntax

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

Parameter Values

 

Parameter

Description

object

Required. Specifies a DateTime object created by date_create().

hour

Required. Specifies the hour for the time.

minute

Required. Specifies the minute for the time.

second

Optional. Specifies the second for the time; defaults to 0.

microseconds

Optional. Specifies the microsecond for the time; defaults to 0.

Technical Details

Return Value:

Returns a DateTime object on success; FALSE on failure.

PHP Version:

5.2+

PHP Changelog:

PHP 7.1: Added the microseconds parameter.

PHP 5.3: Changed the return value from NULL to DateTime.