get_post_datetime

SummerySummery

Retrieve post published or modified time as a DateTimeImmutable object instance.

Syntax

get_post_datetime( int|WP_Post $post = null, string $field = 'date', string $source = 'local' )

DescriptionDescription

The object will be set to the timezone from WordPress settings.

For legacy reasons, this function allows to choose to instantiate from local or UTC time in database. Normally this should make no difference to the result. However, the values might get out of sync in database, typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards compatible behaviors in such cases.

ParametersParameters

$post

(int|WP_Post) (Optional) WP_Post object or ID. Default is global $post object.

Default value: null

$field

(string) (Optional) Published or modified time to use from database. Accepts 'date' or 'modified'.

Default value: 'date'

$source

(string) (Optional) Local or UTC time to use from database. Accepts 'local' or 'gmt'.

Default value: 'local'

ReturnReturn

(DateTimeImmutable|false) Time object on success, false on failure.

SourceSource

File: wp-includes/general-template.php


			

ChangelogChangelog

Changelog
Version Description
5.3.0 Introduced.
Scroll to Top