You can use strtotime()
to convert the time to an integer, and then do a conditional.
// Get the current time
$now = strtotime("now");
// Convert post's modification time to int
$postUpdated = strtotime( $post->post_modified );
// Check if 3 hours has passed, each hour is 60*60 seconds
if ( $now - $postUpdated >= 3*60*60 ) {
// First conditional
} else {
// Second conditional
}
Also, if the time’s format is known ( which is usually 0000-00-00 00:00:00 ), you can directly use strftime()
. Here is a quick example:
$timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time() - 3*60*60);
Now you have a formatted value of 3 hours before, which you can use in date_diff()
.
Related Posts:
- Proper formatting of post_date for wp_insert_post?
- What’s the difference between get_the_time and get_the_date?
- Default timezone hardcoded as UTC?
- How to convert DateTime() to display time based on WordPress timezone setting?
- Running WP Cron on specific local time
- Whats the way to format a date after using get_posts()
- What is the best workaround for supporting all existing DATEs?
- Date format with genitive case of the month name is not working
- Is it safe to use ‘date_default_timezone_set’ in plugin file?
- How do I display posts by day?
- Fixing UTC time – wordpress effects
- Echo Messages By Checking current_time()
- Finding difference in days
- How to get time difference between publish date and now?
- How would I bulk change posting date?
- filter date and time to differents time zone
- How do I create a dynamically-updated copyright statement?
- How do you format the date as a two digit year? (ex. “10.12.10” instead of “10.12.2010”)
- How can I display the current time? [closed]
- Creating a function within functions.php to change the date
- Relative time – how to calculate difference beween post publish date and current time
- Calculate future date
- WordPress outputs mm/dd but it should be opposite
- php console log speed [closed]
- timestamp and scheduled post irregularities
- Timezone UTC to PST
- How do I set up my blog home page to show only this weeke’s posts automatically?
- UTC/local time in Worpdress
- Convert CST published date time to MST timezone
- Display date and time in comments
- Time Issue xx hours ago
- Get WordPress current date/time
- Separately formatting date elements
- How can i display time minus 6 hours
- Show the_date with link
- Displaying time & date problem
- Should I escape the attributes when using get_month_link?
- Display time as “12:00 noon” instead of “12:00 pm”
- How do I make a page not visible at a certain time? [closed]
- How get exact time difference
- wordpress blog posts’s time
- Where does the time get pulled from in the_time()
- Human time difference in months instead of days. How?
- Display posts starting from today date
- Separating publish date and last modified
- Why do I need to set my PHP timezone when it’s already set in WordPress?
- Compare date fails when date is in next year [closed]
- How to setup language of a date in a plugin
- Default Timezone setting in WordPress – is that global?
- Problems with the_time,the_date, get_the_time
- admin end post published time display not working correctly
- Comparing Time with the_time();
- Date time doesn’t show correctly in qTranslate [closed]
- Timed post and tweet?
- wp_dropdown_categories by date?
- WordPress Translate Date Function is giving Error
- Apply filters on date format
- How to fix mysql2date() for 5.3.2 version?
- Incorrect display of bbpress forum topics & replies
- Render the published date/time formatted in ISO 8601 using Timber (.twig)
- Change the year of the whole site
- Display datetime in user’s timezone
- Calculate how much time passed comparing WordPress comment and current time
- Pull ‘Popular Posts’ within specific timeframe
- Block post updates and deletion after a set period
- Replicate the_date function when using a custom field
- Change the counter in terms of date
- Comment time is same as the post time
- Query sub subpages based on specific date?
- Adding a class to last post in the_date
- Can someone explain why wordpress uses two column for storing time values?
- Standard API for rendering a date form
- Display the last date, regardless of articles
- Date is showing in unreadable format. How to convert to readable date?
- Unable to select an old date in wordpress
- human_time_diff() returns “48 years ago” for all comments
- How to get year, month and hour in WordPress?
- How to remove published date from RSS feed
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- post_date_gmt and post_date [duplicate]
- Custom Field sort not working (WP 3.8.1)
- Compare WP Custom Field date
- Last time a user logged in
- Displaying the Month and Year that a page was Created?
- Changing wordpress publication date to ACF date and time picker date not working
- Print last modified date only on posts
- date/time-picker and file upload (image) fields for custom fields (e.g. with more fields)
- Time Based change of image
- Copyright: Get first and last date of post type
- Paginated Archives or Loop by Month
- convert time to WordPress user’s local time
- Shortcode function doesnt work without caption
- Access last visit time to a post
- PHP time function ($today) for GMT +1
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Hide publish date when update date
- How to display time when page is created and edited
- Sorting meta box values by start- and enddate and all dates in between
- Time sort with meta_key using UNIX timestamp failing due to date differences
- How do I convert a custom field to a php date format? [closed]