You create two date objects and compare with the diff()
methode.
$from = new DateTime( '1970-01-01' );
$to = new DateTime('today');
$years = $from->diff($to)->y;
$months = $from->diff($to)->m;
echo $years . ' years and ' . $months . ' months.';
=> 46 years and 1 months.
Related Posts:
- Get date numerical and separate?
- Print last modified date only on posts
- Get date function not working
- Build a content and excerpt grid loop with paging and options for # of posts
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- WordPress returns a wrong date
- How to add 2 posts under another post? Formatting should be intact
- Unable to set right time in admin and frontend template
- WP_Query meta_query results date by date
- wrong php date()?
- Use wp_get_recent_posts with search term
- Remove query string specific key value
- display month in french in wordpress/php?
- Displaying the Month and Year that a page was Created?
- How to prevent WP_Query function from returning all posts when empty?
- Display a specific category of products in shop page and disable code for specific actions
- Get users that likes the post
- Remove echo from shortcode
- Security for data obtained from the database
- Find hours between post_date and post_date_gmt
- How to get User Time Zone in WordPress?
- How do I check or test a WordPress Auto Year Change Script?
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- change the default order of posts only for specific categories
- Post not populating for custom post type based on category selection
- Custom query vars filters problem with pagination
- How to get post category list as select in front-end?
- Displaying Event within two given time frames
- Let current user know pending posts counts using wp_query
- Output product category link from WP_Query
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- “pre_get_posts” orderby custom date field in different format?
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- How to exclude meta no index pages from wp_list_pages
- WP query posts BUT show the most recent and one per author
- Ajax filter with loadmore button
- posts_per_page displays only 2 posts instead of 4 posts
- WordPress wrong dates bug
- Delete post meta by serialized meta value
- Modify post image in full size
- Can’t add to time? [closed]
- WP_Query To Display Product Of Brand On Taxonomy Page
- Custom Post type Ajax search results
- Ordering / grouping posts by datepicker ACF
- My query keeps looping infinitely ! how to stop it?
- Adding a number to a date
- How can I display a query in a page?
- insert thumbnail image from php script
- Weird Behaviour: Not all WordPress Posts appearing
- List sibling pages widget, exclude current page
- How to get category pages to look like a certain archive page?
- How to modify this function to exclude also the post belonging to a specific category?
- a problem in class in class-wp-hook.php
- Convert custom field date format to “WordPress default”
- /page/2/ redirect to 404
- Add adjacent post function inside custom recent post function
- wp_logout action hook is not firing
- How to change post date and post time in WordPress automatically with a function
- Date not working correctly
- Developing a “fallback” for empty wp_query results based on post dates
- How can I count ACF sub_field with a certain value
- Enqueing External JS on the remote server JS
- add_filter function concatenate string and locate_template function
- Personalize checkout text
- get_current_site() is undefined
- How to get current post category details inside “loop”?
- Custom route and query
- CSS change in woo commerce Place Order Text [closed]
- iframe not showing in content on blog page
- How do I create a function that modifies a message in the wp-login.php file?
- Cant display an image via PHP in wordpress
- Co-Authors Plus: How do I get all authors with a query?
- Template Loop – add switch case php
- Get user custom field value on function.php
- Why i can’t get custom fields value or post ID via Ajax?
- WP All Import / Update stock quantity from multiple XML files
- How to use mysql LIKE with wpdb?
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- Reading settings in the home page precisely home.php
- woocommerce related product title length
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Show all tags within a category?
- entire JS folder not loading in a WP theme
- Passing an array into WP_Query as a variable
- List post by title length
- Custom post type permalinks do not appear using the link functions
- Function for simple math doesn’t work what am I doing wrong? [closed]
- Open and closed function [closed]
- WordPress check if current taxonomy has child
- WordPress meta_query >= &
- extract serialized array to use for wp-query
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- WP_Query multiple post results
- get post id from wp_insert_post for get_template_part
- Fetching Initials of the Commentator in the WordPress Website
- Display css ONLY on most recent post of specific category?