-5

I have 2 variables in a PHP script:

$birthday = "1977-10-03";

$now = time();

How do I calculate days remaining before the birthday ($daysRemaining = ?)

Jimmy Sawczuk
  • 13,488
  • 7
  • 46
  • 60
seby
  • 15
  • 2
  • 8
  • Please ONLY post a question on StackOverflow after you have done your research. Please edit your question to include attempts that have failed. – Sumurai8 Sep 04 '13 at 14:33

2 Answers2

0

try this:

$birthday = strtotime("1977-10-03");
$now = time();
$datediff = $now - $birthday;
$daysRemaining = floor($datediff/(60*60*24));
echo $daysRemaining;
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
  • Hi, this does not seems to work, it gives me a big number. i want the remaining days in the current year tks – seby Sep 04 '13 at 14:51
0

Duplicate Date Difference in php on days?

EDITED:

$diff=$date-time();//time returns current time in seconds
$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day)
$hours=round(($diff-$days*60*60*24)/(60*60));

Is this how you wanted?

$birthday = "1977-9-10";
$cur_day = date('Y-m-d');
$cur_time_arr = explode('-',$cur_day);
$birthday_arr = explode('-',$birthday);

$cur_year_b_day = $cur_time_arr[0]."-".$birthday_arr[1]."-".$birthday_arr[2];

if(strtotime($cur_year_b_day) < time())
{
    echo "Birthday already passed this year";
}
else
{
    $diff=strtotime($cur_year_b_day)-time();//time returns current time in seconds
    echo $days=floor($diff/(60*60*24));
}
Community
  • 1
  • 1
rAjA
  • 899
  • 8
  • 13
  • Hi, this does not seems to work, it gives me a big number. i want the remaining days in the current year – seby Sep 04 '13 at 14:51