I am having a problem getting the code below to work basically what I am doing is checking to see if the value of a time stamp variable that is in 24 hour format is after 1:00 PM if it is then convert it to the 12 hour format. When I have the value echoed back it always says 6:00 PM. What is the problem?
Here is how I get the $timeToday variable
$timeToday = date("H:i A");
Here is the code that is not working correctly:
if ($timeToday>"12:59"){
$timeConverted = date("h:i A", strtotime($timeToday));
echo "You clocked out at: " . $timeConverted . "<br>";
} else {
echo "You clocked out at: " . $timeToday . "<br>";
}
You’re comparing 2 strings, which do not have the same format. $timeToday is AM/PM, while you’re comaring it to a 24h clock.
Also the code would print AM/PM either way. If I understand you correctly, you don’t want to print AM, only PM.