darkfreaks Posted November 30, 2008 Share Posted November 30, 2008 okay the problem i am having is that it is subtracting a year somehwere so when it is sposed to read Age:1 it outputs age:0 ??? <?php $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December"); $bdayMonth = $exBday[0]; if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); } $exBday[0] = $months[$bdayMonth]; $birthday = "$exBday[0] $exBday[1], $exBday[2]"; $userAge = $this_year - $exBday[2]; if ($this_month < $exBday[0]) { $userAge = $userAge - 1; } if (($this_month == $exBday[0]) AND ($today < $exBday[1])) { $userAge = $userAge - 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/ Share on other sites More sharing options...
genericnumber1 Posted November 30, 2008 Share Posted November 30, 2008 Well, one logical problem you have is that you're comparing $this_month (which I assume is an int) to $months[$bdayMonth] (which is a string). I haven't looked too much into it, so there may be other issues... but there are a lot of undefined variables in just what you've showed us. Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702050 Share on other sites More sharing options...
sKunKbad Posted November 30, 2008 Share Posted November 30, 2008 I played with your script, and here was the problem that I ran into: where $this_month is compared to $exBday[0], $exBday[0] is a string which the value is a name of a month, like "June". You need to keep $exBday a number value if you want to compare these variables. I admit, I had to add to your script just to figure this out. If you would supply more code I could probably come up with a solution. Here is what I was working with: <?php $exBday[0] = 6; $exBday[1] = 28; $exBday[2] = 2003; $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December"); $bdayMonth = $exBday[0]; if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); } $exBday[0] = $months[$bdayMonth]; $birthday = "$exBday[0] $exBday[1], $exBday[2]"; echo "<br>The birthday variable = " . $birthday; $this_year = 2008; $this_month = 5; $userAge = $this_year - $exBday[2]; echo "<br>The variable userAge = " . $userAge; if ($this_month < $exBday[0]) { $userAge = $userAge - 1; } if (($this_month == $exBday[0]) AND ($today < $exBday[1])) { $userAge = $userAge - 1; } echo "<br>The variable userAge is now = " . $userAge; ?> Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702056 Share on other sites More sharing options...
darkfreaks Posted November 30, 2008 Author Share Posted November 30, 2008 Variables you need: <?php $this_month = date("n",$date); // MONTH 1-12 $this_year = date("Y",$date); // YEAR YYYY $date = date("U"); // TIMESTAMP $timestamp = $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702062 Share on other sites More sharing options...
sKunKbad Posted November 30, 2008 Share Posted November 30, 2008 Where does $date come from. When I run as-is, all I get is: 12 = this_month, and 1969 = this_year Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702069 Share on other sites More sharing options...
darkfreaks Posted November 30, 2008 Author Share Posted November 30, 2008 <?php $date = date("U"); // TIMESTAMP $timestamp = $date;?> Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702071 Share on other sites More sharing options...
sKunKbad Posted November 30, 2008 Share Posted November 30, 2008 THIS WORKS: <?php $exBday[0] = 11; $exBday[1] = 29; $exBday[2] = 2003; $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December"); $bdayMonth = $exBday[0]; if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); } $exBday2[0] = $months[$bdayMonth]; $birthday = "$exBday2[0] $exBday[1], $exBday[2]"; echo "<br>The birthday variable = " . $birthday; $this_month = (int) date("n"); // MONTH 1-12 $this_year = (int) date("Y"); // YEAR YYYY $today = (int) date("j"); echo "<br>$this_month = this_month, and $this_year = this_year, and today is $today"; $userAge = $this_year - $exBday[2]; echo "<br>The variable userAge = " . $userAge; if ($this_month < $exBday[0]) { $userAge = $userAge - 1; } if (($this_month == $exBday[0]) && ($today < $exBday[1])) { $userAge = $userAge - 1; } echo "<br>The variable userAge is now = " . $userAge; ?> Quote Link to comment https://forums.phpfreaks.com/topic/134818-solved-dont-understand-birthday-script/#findComment-702084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.