How can one troubleshoot receiving a result of -1 when using strtotime() in PHP?
When receiving a result of -1 when using strtotime() in PHP, it typically means that the date string passed to strtotime() is not in a valid format. To troubleshoot this issue, ensure that the date string is in a format that strtotime() can recognize, such as "Y-m-d H:i:s" or "Y-m-d". Also, check for any typos or incorrect date formats in the input string.
$date_string = "2022-12-31";
$timestamp = strtotime($date_string);
if ($timestamp === false || $timestamp === -1) {
echo "Invalid date format or value";
} else {
echo "Timestamp: " . $timestamp;
}