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
- How to register images uploaded via FTP in media library?
- how to get permalink structure with php
- Archive listing of posts by publish year (multiple years)
- The values of custom fields are not available functions.php
- How can I loop into two different DIVS without repeating the DIVs
- Removing unnecessary wordpress files
- WP_Query use for a filter with multiple Taxonomies and Terms
- Use is_product_category() properly
- Changing Woocommerce flat rate every nth number of items
- Convert all images to PNG on file upload
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Custom page archive query by url var calling page twice on one of my custom queries?
- WP Query with custom Shortcode
- Using fwrite() and “a” appends multiple times instead of once
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- How do I add custom bulk actions to multiple custom post types?
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- Keyword checking in Gravity Forms
- how to refresh div on template part?
- Child page menu in sidebar
- Detecting if parent page has gallery
- Help with WordPress function inside a shortcode
- Convert a string into a decimal number for use in query
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Removing “Powered by” footer using child theme PHP [closed]
- How to style injected code in header section?
- Include a file that has a function in it
- SQL error with custom query
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- Contain multiple page templates in one PHP custom template file in WordPress?
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Custom plugin: how do I call a PHP file if settings option is set to true?
- How to put 2 php codes in functions.php without site crashing
- Query to show average # of months all accounts with specific role have been active
- WP HTTP API call response
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Query doesn’t display text data with apostrophes
- Custom meta box save values issues – Deprecated: Function ereg() and more
- Ninja Forms – pull in some post related information
- Functions are causing errors
- Global variables and re-use
- Link to external page has wordpress blog-url inside
- AJAX: WordPress filters inside $html do not work as intended
- Appending an ACF custom field to the page title