DateTime::format

(PHP 5 >= 5.2.0, PHP 7)
Returns date formatted according to given format
public string DateTime::format ( string $format )

Object oriented style

public string DateTimeImmutable::format ( string $format )
public string DateTimeInterface::format ( string $format )

Procedural style

string date_format ( DateTimeInterface $object , string $format )

Returns date formatted according to given format.

Parameters:
object

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

format

Format accepted by date().

Returns:

Returns the formatted date string on success or FALSE on failure.

Examples:
DateTime::format() example

Object oriented style

<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>

Procedural style

<?php
$date = date_create('2000-01-01');
echo date_format($date, 'Y-m-d H:i:s');
?>

The above example will output:

2000-01-01 00:00:00
See also:

date() -

doc_php
2016-02-24 15:56:23
Comments
Leave a Comment

Please login to continue.