PHP check if date is 30 days in the past

旧时模样 提交于 2021-01-27 04:17:03

问题


I'm having a bit of a problem here.

I insert a date into the database: date_last_applied.

I can just call this by using $row['date_last_applied'], of course. Now, I need to check if this inserted date was 30 days ago and if so, execute an 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']);

}

That's about all I have.. I tried some things, but they all failed. :(


回答1:


if ($date < strtotime('-30 days'))

If you are only performing actions on dates older than 30 days, you should use Marco's solution.




回答2:


You could do it via SQL getting only dates in 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)


来源:https://stackoverflow.com/questions/8080760/php-check-if-date-is-30-days-in-the-past

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!