the-botman Posted May 28, 2010 Share Posted May 28, 2010 hi guys, this code shows how many days left untill the users birthday using the date of birth, now it works if your birthday has not past but if it has it gives a - reply is there anyway around this? here is the code [code $Date_Day = GetPost('Day'); $Date_Month = GetPost('Month'); $Date_Year = GetPost('Year'); $hour = "23"; $h = mktime(0, 0, 0, $Date_Month, $Date_Day, $Date_Year); $d = date("F dS, Y", $h) ; $w= date("l", $h) ; $Birthday= date("-l", $h) ; $today = mktime(); $birthDateThisYear = mktime(0,0,0,$month,$day); if ($birthDateThisYear<$today) { $nextBirthDate = mktime(0,0,0,$Date_Month,$Date_Day,date('Y',$today+1)); } else{ $nextBirthDate = $birthDateThisYear; } $daysTillNextBirthday = floor(($nextBirthDate-$today)/60/60/24); echo '<font face="Verdana" size="2">There are: <b>'.$daysTillNextBirthday.'</b> left Untill your birthday</font><br>'."\n";] Link to comment https://forums.phpfreaks.com/topic/203202-time-problem/ Share on other sites More sharing options...
teamatomic Posted May 28, 2010 Share Posted May 28, 2010 Check if the Bday is past, if it is increase the year by 1 or you could take the -days and subtract it from 365. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/203202-time-problem/#findComment-1064690 Share on other sites More sharing options...
the-botman Posted May 29, 2010 Author Share Posted May 29, 2010 i tried this but still no success $Date_Day = GetPost('Day'); $Date_Month = GetPost('Month'); $Date_Year = GetPost('Year'); $end = mktime(0,0,0,$Date_Month,$Date_Day,$Date_Year); $today= mktime(date("G"),date("i"),date("s"),date("m"),date("d"),date("Y")); $days=($end-$today)/86400; if ($days>0) { $nextBirthDate = mktime(0,0,0,$Date_Month,$Date_Day,date("Y")); } else{ $nextBirthDate = mktime(0,0,0,$month,$day,date("Y")+1); } $daysTillNextBirthday = floor(($nextBirthDate-$today)/60/60/24); Link to comment https://forums.phpfreaks.com/topic/203202-time-problem/#findComment-1064994 Share on other sites More sharing options...
ChemicalBliss Posted May 29, 2010 Share Posted May 29, 2010 I think you could simplify this: $today = time(); $birthdate = mktime(0,0,0,GetPost('Month'),GetPost('day'),GetPost('Year')); $birthdaythis = mktime(0,0,0,GetPost('Month'),GetPost('day')); // birthday this year $birthdaynext = mktime(0,0,0,GetPost('Month'),(date('Y',$time)+1)); // birthday next year if($today < $birthdate){ // echo('Not born yet'); }elseif($today == $birthdate){ // echo('Hurrah, a birth'); }elseif($today < $birthdaythis){ $days = floor(($birthdaythis - $today) / 60 / 60 / 24); echo('Birthday coming at '.date('d/m/y',$birthdaythis)." (".$days." Days)"); }elseif($today > $birthdaythis){ $days = floor(($birthdaynext - $today) / 60 / 60 / 24); echo('Birthday coming at '.date('d/m/y',$birthdaynext)." (".$days." Days)"); }elseif($today == $birthdaythis){ // echo('Hurrah, Birthday Today!'); }else{ // echo('Logic error?'); } I think thats what you're after.. -cb- Link to comment https://forums.phpfreaks.com/topic/203202-time-problem/#findComment-1065009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.