Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 533
David G Avatar asked Jan 16 '13 23:01

David G


1 Answers

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.

like image 169
Jim Avatar answered Sep 29 '22 18:09

Jim