I had to write a PHP script that will countdown the days, hours, and minutes until my next birthday. This script must work year round. I thought I had done this but my teacher informed me that what I wrote will not work between November 13 and December 31, November 13 being my birthday.
This is the code I submitted:
[php]<?php
$a = getdate();
extract($a);
$bday = mktime(0, 0, 0, 11, 13, $year);
$today = time ();
$difference =($bday-$today);
$days =(int) ($difference/86400);
$hours =(int) ($difference % 86400 / 3600);
$minutes =(int) ($difference % 86400 % 3600 / 60);
echo “My birthday is in $days days, $hours hours, and $minutes minutes.”;
?>[/php]
PHP.net helped a lot, as always. To be honest, I have no idea what I could do to fix it. I feel like I’ve overlooked something simple. Any help would be super appreciated (I probably should not have taken programming as an elective, but it’s fun to see a program work).