Jump to content

Majestic1985

New Members
  • Posts

    2
  • Joined

  • Last visited

Majestic1985's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I thought I made the correct changes, but I'm still getting an incorrect number. Your hint helped me realize what may be wrong, but I think I've been working on this problem for so long, that I can't see the answer right in front of me. Could you elaborate a bit more. Thanks again.
  2. Hello All, I'm a student currently enrolled in a PHP course, and our instructor has told us to create code that would accept a users birthday and then calculate how many days from today is their next birthday. The program returns a value, but the value is incorrect. I should never receive a value over 365 days. Example: Input: 04/11/1985 Today's Date is 11/9/2016 Output (should be): "You have 153 days until your next Birthday" Actual Output: "You have 212 days until your next Birthday" What did I do wrong? Thanks in advance for any assistance Michelle <?php $johnsBirthday = $_GET ['JohnBday']; $jakesBirthday = $_GET ['JakeBday']; $john_bday = new DateTime($_GET['JohnBday']); $jake_bday = new DateTime($_GET['JakeBday']); $today_date = new DateTime(); switch (true) { case ($john_bday < $today_date) : $today_date->setDate($john_bday->format('Y'), $today_date->format('m'), $today_date->format('d')); break; case ($today_date < $john_bday) : $john_bday->setDate($today_date->format('Y'), $john_bday->format('m'), $john_bday->format('d')); break; } switch (true) { case ($today_date < $jake_bday) : $jake_bday->setDate($today_date->format('Y'), $jake_bday->format('m'), $jake_bday->format('d')); break; case ($jake_bday < $today_date) : $jake_bday->setDate($today_date->format('Y'), $jake_bday->format('m'), $jake_bday->format('d')); break; } $john_interval = $john_bday->diff($today_date); $john_diff = $john_interval->format('%a'); echo "John you have $john_diff days until your next Birthday</br>"; $jake_interval = $jake_bday->diff($today_date); $jake_diff = $jake_interval->format('%a'); echo "Jake you have $jake_diff days until your next Birthday</br>"; if ($johnsBirthday < $jakesBirthday) { echo "John is older than Jake</br>"; } elseif ($johnsBirthday > $jakesBirthday) { echo "Jake is older than John</br>"; } else { echo "Jake and John are twins"; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.