简体   繁体   English

如何检查日期是否已过期PHP中的数值

[英]How do I check if a date is past due a numeric value in PHP

Hey guys so lets say I have a member who put 20 days. 大家好,我可以说有一位成员花了20天的时间。 So after 20 days if there member, lets say did not log in it would change there status. 因此,如果有成员20天后,让我们说不登录它将更改那里的状态。 But only based on a status change date which is written in MySQL database as year-month-day . 但是仅基于状态更改日期,该状态更改日期写在MySQL数据库中为year-month-day So if 20 days have done by his status change date than his status would change. 因此,如果在他的状态更改日期之前完成了20天,那么他的状态将会更改。

If you could give me a hand on how to do this I would appreciate it! 如果您能帮助我做到这一点,我将不胜感激!

David 大卫

UPDATE: 更新:

code: 码:

$newStatus = "Non-Active - Driver Chose Non-Compliance";

    $sql = "SELECT username,ATF FROM members WHERE username = 'test'";
    $getcsvuser = $DBH->prepare($sql);
    $getcsvuser->execute();
    while($row = $getcsvuser->fetch(PDO::FETCH_ASSOC)){

        $memusername = $row['username'];
        $memATF = $row['ATF'];
        if ($memATF != 0 || $memATF != "0")
        {
        $tsql = "SELECT username,status,memberview ,statuschangedate FROM csvdata WHERE memberview =:user";
        $tgetcsvuser = $DBH->prepare($tsql);
        $tgetcsvuser->execute(array(':user' => $memusername));
        while($trow = $tgetcsvuser->fetch(PDO::FETCH_ASSOC)){

            $csvstatus = $trow['status'];
            $csvusername = $trow['username'];
            $csvdate = $trow['statuschangedate'];

            if($csvstatus == "Open" || $csvstatus == "Enrolled - Policyholder Follow-Up Required" || $csvstatus == "Enrolled - Employee Follow-Up Required" || $csvstatus == "Non-Active - Insurance Cancelled" || $csvstatus == "Non-Active, Unable to Monitor - Incidental Business use Exclusion" || $csvstatus == "Non-Active - Employee Not Covered Under Listed Policy" || $csvstatus == "Non-Active - PolicyHolder Cancelled Additional Interest")
            {

                $newsql = "UPDATE csvdata SET status = :newstatus WHERE statuschangedate < NOW() - INTERVAL :atf DAY AND username =:mem";
                $newgetcsvuser = $DBH->prepare($newsql);
                $newgetcsvuser->execute(array(':newstatus' => $newStatus, ':atf' => $memATF, ':mem' => $csvusername));
                while($rrow = $newgetcsvuser->fetch(PDO::FETCH_ASSOC)){
                    echo "working";
                }
            }

        }
        }

    }

It can be a combination of two things: 它可以是两件事的组合:

mysql to update the users, that are to be changed: mysql更新要更改的用户:

update
  members
set
  status = 'foo'
where
  status_change_date < NOW() - INTERVAL 20 DAY

The second part would be a cron job, that run that query daily. 第二部分是cron作业,每天运行该查询。

How about that: 那个怎么样:

UPDATE tablename
SET inactive = 1
WHERE date_field < DATE_SUB(NOW(), INTERVAL 20 DAY)

You could run this query as a cronjob once a night. 您可以每晚一次作为cronjob运行此查询。

So this can be done without using PHP logic except for executing this SQL query. 因此,除了执行此SQL查询外,无需使用PHP逻辑即可完成此操作。

I didn't test this but it should be close. 我没有测试过,但是应该很接近。

//$dbVal = $row["databaseColumn"];
$dbVal = "2013-01-24";  //For example
$now = Date();

$diff = abs($now - strtotime($dbVal));

$daysSince = floor(($diff/(60*60*24));
if ($daysSince >20){
    //Set status in DB;
}

incorporating @popnoodles solution: 合并@popnoodles解决方案:

//$dbVal = $row["databaseColumn"];
$dbVal = "2013-01-24";  //For example
$expireTime = 20;

$diff = strtotime($dbVal) - strtotime("today - $expireTime days");
if ($diff < 0 ){
    //Set status in DB;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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