PHP checks if date has 30 days in the past

I have a problem here.

I am inserting a date into the database: date_last_applied .

I can simply call it using $row['date_last_applied'] , of course. Now I need to check if this added date was 30 days ago , and if so, do the action.

 $query = "SELECT date_last_applied FROM applicants WHERE memberID='$id'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $date = strtotime($row['date_last_applied']); } 

This is about everything that I have .. I tried something, but they all failed. :(

+4
source share
2 answers
 if ($date < strtotime('-30 days')) 

If you perform actions only on dates older than 30 days, you should use the Marco solution.

+15
source

You can do this through SQL, getting only dates from the last 30 days.

 SELECT date_last_applied FROM applicants WHERE memberID = your_id AND date_last_applied BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW() 

or older than 30 days

 SELECT date_last_applied FROM applicants WHERE memberID = your_id AND date_last_applied < DATE_SUB(NOW(), INTERVAL 30 DAY) 
+9
source

Source: https://habr.com/ru/post/1380588/


All Articles