I’d been using a script to update a database based on the difference between two dates without any problem until 11 February. Then all of a sudden strange thihngs started happening without any changes being made to the script.
The idea is to update some records in a database which were last updated one day ago, and update others which were last updated 7 days ago. This is what I was using:
$datenew7 = new DateTime("now");
$datenew7->modify("-7 day");
$expirydate7 = $datenew7->format("d/m/Y H:i:s");
$datenew1 = new DateTime("now");
$datenew1->modify("-1 day");
$expirydate1 = $datenew1->format("d/m/Y H:i:s");
$strSQL1="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='p' AND dateupdated < #" . $expirydate1 . "#";
$strSQL7="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='s' AND active='a' AND dateupdated < #" . $expirydate7 . "#";
The first query still works fine, but the second query updates those records every time the script is run, regardless of the number of days which have elapsed.
Interestingly, if I change “-7 day” to “-4 day” or less, it works ok. Anything above “-5 day” doesn’t work.
I since searched here and found a simpler way to get the variables, so changed them to:
$expirydate7 = date('d-m-Y H:i:s', strtotime("-3 day"));
$expirydate1 = date('d-m-Y H:i:s', strtotime("-1 day"));
…but still the same result. I’ve searched everywhere but no joy. Any help greatly appreciated.
The proper date format is
Y-m-d H:i:s. Try using that format and see if it works.