I have searched through SO but the answers that I've tried doesn't seem to solve my problem. I have this simple code snippet where the user will input a numeric date, and a month, and the app will return the corresponding Zodiac Sign.
$birthdate = $_POST["birthdate"];
$birthmonth = (ucwords(strtolower($_POST["month"])))
//validations here. . .
$tmp = $birthmonth . " " . $birthdate;
$tmp2 = date_create_from_format('M j', $tmp);
$formatted_dob = date_format($tmp2, 'm-d-Y');
$dob = strtotime($formatted_dob);
echo $formatted_dob;
if ($dob >= strtotime('01-20-2016') && $dob <= strtotime('02-18-2016')) {
echo "Aquarius";
} elseif ($dob >= strtotime('02-19-2016') && $dob <= strtotime('03-20-2016')){
echo "Pisces";
}
Those echo
stuff outside the if-else
block are working fine, however if I input a value of 25 and February (which later on results to 02-25-2016
), it always output Aquarius
. How do you compare two strtotime
values?
I've tried using DateTime
object but it only gives me an error, which is another story. Thanks in advance.