简体   繁体   中英

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. So after 20 days if there member, lets say did not log in it would change there status. But only based on a status change date which is written in MySQL database as year-month-day . So if 20 days have done by his status change date than his status would change.

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:

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.

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.

So this can be done without using PHP logic except for executing this SQL query.

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:

//$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;
}

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