Title: get_post_timestamp
Published: November 12, 2019
Last modified: February 24, 2026

---

# get_post_timestamp( int|WP_Post $post = null, string $field ): int|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#wp--skip-link--target)

Retrieves post published or modified time as a Unix timestamp.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#description)󠁿

Note that this function returns a true Unix timestamp, not summed with timezone 
offset like older WP functions.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post ID or post object. Default is global `$post` object.

Default:`null`

`$field`stringoptional

Published or modified time to use from database. Accepts `'date'` or `'modified'`.

Default `'date'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#return)󠁿

 int|false Unix timestamp on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#source)󠁿

    ```php
    function get_post_timestamp( $post = null, $field = 'date' ) {
    	$datetime = get_post_datetime( $post, $field );

    	if ( false === $datetime ) {
    		return false;
    	}

    	return $datetime->getTimestamp();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/general-template.php#L2984)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/general-template.php#L2984-L2992)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#related)󠁿

| Uses | Description | 
| [get_post_datetime()](https://developer.wordpress.org/reference/functions/get_post_datetime/)`wp-includes/general-template.php` |

Retrieves post published or modified time as a `DateTimeImmutable` object instance.

  |

| Used by | Description | 
| [WP_Posts_List_Table::column_date()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/column_date/)`wp-admin/includes/class-wp-posts-list-table.php` |

Handles the post date column output.

  | 
| [WP_Media_List_Table::column_date()](https://developer.wordpress.org/reference/classes/wp_media_list_table/column_date/)`wp-admin/includes/class-wp-media-list-table.php` |

Handles the date column output.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_post_timestamp/?output_format=md#comment-content-5252)
 2.   [Sam Kent](https://profiles.wordpress.org/oxocube/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_post_timestamp/#comment-5252)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_timestamp%2F%23comment-5252)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_timestamp%2F%23comment-5252)
 4. How to get the published and modified date with `get_post_timestamp()` and then
    convert it into a readable format.
 5.     ```php
        <?php
        function published_modified_date() {
    
        	// UNIX published date
        	$unix_published_date = get_post_timestamp( '', 'date' );
    
        	// UNIX modified date
        	$unix_modified_date = get_post_timestamp( '', 'modified' );
    
            // Convert from UNIX timestamp into readable date
            // Reference: https://developer.wordpress.org/reference/functions/date_i18n
        	$published_date = date_i18n( get_option( 'date_format' ), $unix_published_date );
        	$modified_date = date_i18n( get_option( 'date_format' ), $unix_modified_date );
    
            // Convert from UNIX timestamp into full date/time (ISO)
            // Reference: https://wordpress.org/support/article/formatting-date-and-time
        	$full_published_date = date_i18n( 'c', $unix_published_date );
        	$full_modified_date = date_i18n( 'c', $unix_modified_date );
    
            ?>
    
        	<span class="published"><time datetime="<?php echo $full_published_date; ?>"><?php echo $published_date; ?></time></span>
    
            <?php
            // If modified date is greater than published date by 1 day 
            if ( $unix_modified_date > $unix_published_date + 86400 ) { ?>
        		<span class="modified">Modified on: <time datetime="<?php echo $full_modified_date; ?>"><?php echo $modified_date; ?></time></span>
        	    <?php
            }
    
        }
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_timestamp%2F%3Freplytocom%3D5252%23feedback-editor-5252)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_timestamp%2F)
before being able to contribute a note or feedback.