get_the_date() WP 3.0.0
Gets the creation date of the current post. you can specify an arbitrary date output format. Used in a WordPress loop.
This function is different from the_date(). It always return a result (date), even if the next post (in the loop) was published on the same day (the_date() will skip such date output).
You can use the get_the_date filter to change the output string.
Works based on: mysql2date()
Basis of: the_date()
1 time = 0.000723s = slow | 50000 times = 1.44s = fast | PHP 7.2.5, WP 4.9.6
Hooks from the function
Return
String/false. Date the current post was written. False on failure.
Usage
get_the_date( $format, $post );
- $format(string)
- PHP date format. option.
Default: 'date_format' - $post(int/WP_Post)
- Post ID or WP_Post object.
Default: current post
Examples
#1 A basic example
Display the date of the post within the WordPress Loop.
<span class="entry-date"><?php echo get_the_date(); ?></span>
#2 Specify an arbitrary date format
Post published at <?php echo get_the_date('n-j-Y'); ?>
Displays: Post published at 11-6-2018
Changelog
Since 3.0.0 | Introduced. |
Code of get_the_date() get the date WP 5.6
Related Functions
From tag: date time
- comment_date()
- comment_time()
- current_time()
- date_i18n()
- get_comment_date()
- get_comment_time()
- get_date_from_gmt()
More from category: Posts, pages...
- edit_post_link()
- get_delete_post_link()
- get_edit_post_link()
- get_permalink()
- get_post_field()
- get_post_status()
- get_sample_permalink()
- get_the_content()
- get_the_excerpt()
More from Template Tags: Posts, Pages, ...
- body_class()
- get_post_format()
- have_posts()
- in_the_loop()
- next_image_link()
- next_post_link()
- next_posts_link()
- post_class()