Espen Arnoy
Espen Arnoy

Reputation: 157

How to check if a Wordpress post date is at least 7 days old

I´d like to create a function that checks if a "post" (wordpress) is older than 7 days. I have the following code so far:

function is_old($start) {

    $now = date("Y-m-d");

}

$start contains the date which I want to check if is more than 7 days prior to $now. How can I do this?

Upvotes: 2

Views: 987

Answers (2)

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124778

If $start is a date, this works:

function is_old($start) {
    return strtotime($start) < strtotime('-1 week');
} 

If $start is a timestamp, you can omit the first strtotime.

Upvotes: 7

MatTheCat
MatTheCat

Reputation: 18721

If $start is a timestamp you have just to do

$days_old = (time() - $start) / 86400

Upvotes: 1

Related Questions