Using WordPress ‘get_post_modified_time()’ PHP function

The get_post_modified_time() WordPress PHP function retrieves the time at which the post was last modified.

Usage

get_post_modified_time( $format, $gmt, $post, $translate );

Parameters

  • $format (string) (Optional) – Format to use for retrieving the time the post was modified. Accepts ‘G’, ‘U’, or PHP date format. Default is ‘U’.
  • $gmt (bool) (Optional) – Whether to retrieve the GMT time. Default is false.
  • $post (int|WP_Post) (Optional) – Post ID or post object. Default is the global $post object.
  • $translate (bool) (Optional) – Whether to translate the time string. Default is false.

More information

See WordPress Developer Resources: get_post_modified_time()

Examples

Get a timestamp for the current post

This example retrieves a Unix timestamp for the current post’s last modified time.

echo get_post_modified_time(); // 1490121048

Get full date and time in the current timezone

This example retrieves the full date and time in the current timezone for the current post’s last modified time.

echo get_post_modified_time('F d, Y g:i a'); // "March 21, 2017 12:02 pm"

Get full date and time in UTC

This example retrieves the full date and time in UTC for the current post’s last modified time.

echo get_post_modified_time('F d, Y g:i a', true); // "March 21, 2017 7:02 pm"

Get full date and time in UTC with localization

This example retrieves the full date and time in UTC for the current post’s last modified time, with localization as per WordPress settings.

echo get_post_modified_time('F d, Y g:i a', true, null, true); // "März 21, 2017 7:02 pm"

Get the date in your own language

This example retrieves the date in your own language defined in WordPress by setting the $translate parameter as true.

echo get_post_modified_time('j \d\e F \d\e Y', false, null, true); // "14 de novembro de 2019"