简体   繁体   中英

Checking if a date is within 7 days of the current time

So I have a php function which interacts with a database and pulls data out. However I have a date stamp (in this case an upload date). I want to make it so that if something has been uploaded within the last 7 days, it posts that to users to make them aware of it being 'new'.

So far I have this:

if( strtotime($rows['Date']) > strtotime('now') ) {
    echo '<div class="l-new"><a href="#"><!-- --></a></div>';
}

The $rows thing is taken care of and works from some other code above this line. But this is the line I am concerned with.

I want to say "if the date in the database is older than the current time, and is less than 7 days old, do the following { //echo the stuff about it being new }

Problem is, how do I phrase that if statement to make it within 7 days? Absolutely cannot think of how unfortunately. I'm sure it is quite simple! Thank you

if( strtotime($rows['Date']) > strtotime('-7 day') ) {
    echo '<div class="l-new"><a href="#"><!-- --></a></div>';
}

The strtotime('-7 day') part returns the time 7 days ago.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM