2

I want to store the current time using the update_option and then compare it if the set time was 3 days ago. I want to know in what format I should store the time? and then how can I compare it with current time and find the difference in the days?

3

You should store the time as a unix time stamp then you can use human_time_diff to compare.

echo human_time_diff( get_the_time('U'), current_time('timestamp') );

If the difference is more than 24 hours difference it will return the value in days.

  • I'm using this but it's showing me an extra 8 hours... you wouldn't know what's causing that would you? – Pete Dec 30 '16 at 3:45
  • FIXED: echo human_time_diff(get_the_modified_date('U'), current_time( 'timestamp', 1 )) . ' ago'; – Pete Dec 30 '16 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.