I am coding a project where the dates in the future can be quite a ways in the future. In the project, the number of days ahead is css colored green, behind (today) is coded red and if it is today colored white.
The bulk of the code is below.
$dtAsString = "9/18/2037"
$dueDate = new DateTime($dtAsString);
//0 day calculation
if ( $dueDate->diff(new DateTime())->days == 0 )
{
//white
$css = "white";
return 0;
}
//if not in past, green, otherwise red
//die("date=" . $dtAsString . " past:'" . (strtotime( $dueDate ) < time() ) . "' CALC: " . $dueDate->diff()->days);
if ( ( time() < strtotime( $dtAsString ) ) == 1 )
{
//less than today is green
$css = "green";
return $dueDate->diff(new DateTime())->format("%a") * -1;
} else {
//after due date is red
$css = "red";
return $dueDate->diff(new DateTime())->format("%a");
}
If $dtAsString
is 9/18/37 it comes back correctly as ahead of today and colored green
.
However, if I move the year up to 9/1/2097
it is no longer in the future and returns as red
. I originally thought this was an error with the custom date class I was using. But since I removed the date class and am using the raw PHP date objects, I still get the same result.
Has anyone else run into this? Any assistance is very much appreciated.
EDIT 1:35 pm 5/27/2021
In researching PHP's strtotime(), I can confirm it has to do with the fact I am using x86 vs x64. On my test machine it is x86. And because occasionnally I have to use MS ACCESS which library typically is x86 (even though accdb is 64), so is my production system.
Thank you all for your support and quick responses. As I am new to Stackoverflow, I cannot as yet mark any answer as correct or even upvote. But thank you all!