F1Fan Posted November 4, 2008 Share Posted November 4, 2008 OK. Since it is NOT a date format, but rather just plain text, you'll have to extract the date parts and format it yourself in the YYYY-MM-DD format. I think you already had something like that created using explode. $exBday = explode("-", $members_profiles[birthday]); $birthday = "$exBday[2]-$exBday[0]-$exBday[1]"; Then use the $birthday var with that function I gave you. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 Am I right in thinking this?; $exBday = explode("-", $members_profiles[birthday]); $birthday = "$exBday[2]-$exBday[0]-$exBday[1]"; function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate($members_profiles['birthday']); Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 guessing your code - and came with this outcome; http://eaglelegend.com/user_profile.php?game=1&user=maruku it now shows the correct date of birth, but still "38" years old LOL! Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 I just tested this and it works perfectly: $bdate = "05-18-1992"; $exBday = explode("-", $bdate); $birthday = "$exBday[2]-$exBday[0]-$exBday[1]"; function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate($birthday); echo $userAge; Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 ok - so do you mean I change ALL the users dates os births from eg. 05-18-1992 to YYYY-MM-DD? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Yes. If you are wanting to use a date for ANYTHING other than just displaying it, you should really change your DB table column to "date" rather than "varchar." Then extracting it will be easier, and you won't have to re-format the incorrectly formatted date anytime you want to compare it or display it in a different way. YYYY-MM-DD is the programming standard, and strtotime() understands it. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 OK thanks - now, - whoot!! it works http://eaglelegend.com/user_profile.php?game=1&user=maruku - now problem is, if you notice tyhe age is now at the top Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 This is the current code. <?php /* User Profile (user_profile.php) */ $rank_check = 1; $page_title = "User Profile"; include "header.inc.php"; $members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'"); $members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'"); $online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1"); if ($rank == "7") { $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1"); $membersIP = " ($iplog[ip_addr])"; } if (!$members[id]) { die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML"); } if ($members[rank] <= 1) { die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML"); } $gender = $members_profiles[gender]; $genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>"); $gender = $genderArray[$gender]; $mailSettings = $members_profiles[mail_settings]; $mailSettingsArray = array( "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", ""); $mailSettings = $mailSettingsArray[$mailSettings]; $bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>"; $date_registered = date("M j, Y", $members_profiles[date_registered]); $last_visited = date("H:i", $online[last_visit]); $last_visited2 = date("M j, Y @ H:i", $online[last_visit]); $exBday = explode("-", $members_profiles[birthday]); $birthday = "$exBday[2]-$exBday[0]-$exBday[1]"; function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate($birthday); echo $userAge; if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn)) { $onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>"; } else { $onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>"; } $yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'"); $yourNotes = $yourNotes[bud_note]; if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; } $find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'"); if ($find_shop[shop_name]) { $usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>"; } $find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'"); if ($find_gallery[gallery_name]) { $gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>"; } $locationLine = $members_profiles[location]; if (!$locationLine) { $locationLine = "<i>Middle of no where!</i>"; } $getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'"); $getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'"); if ($getclub[id]) { $clubrank = $getClub[position]; if ($clubrank == 1) { $position = "Member"; } if ($clubrank == 2) { $position = "Moderator"; } if ($clubrank == 3) { $position = "Admin"; } $club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>"; } $findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'"); $numUserPets = mysql_num_rows($findPets); $x = 1; while ($getPets = mysql_fetch_array($findPets)) { if ($x < $numUserPets) { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), "; } else { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])"; } $x++; } echo <<<END $openHTML <table bgcolor=#ffffff width=95%> <tr><td> <CENTER> END; echo "<img src='uploads/$members_profiles[avatar_selected]' width=40 height=40> "; echo <<<END <FONT SIZE="+2"><B>$members[display_name]'s Profile</B></FONT></CENTER> <p>$members_profiles[profile]</p> <center><hr width=75% color="$tableOutline"></center> <font size=-1> <P><b>Username:</b> $members[display_name]$membersIP<br> <b>Real name:</b> $members_profiles[real_name]<bR> <b>Birthday:</b> $birthday ($userAge years old!)<br> <b>Location:</b> $locationLine<br> <b>Date Registered:</b> $date_registered<br> <b>Total Referrals:</b> $members_profiles[referrals]<br> <b>Total Posts:</b> $members[post_count] </P> <P><b>Your Notes:</b> $yourNotes</P> <P><b>$numUserPets Pets:</b> $petList</p> <P>$usershop_line<br> $club_line $gallery_line</p> <p><b>Online?</b> $onlineNow</P> </font> <center><table><tr><td> <form action=mail_send.php?game=$game&send_to=$members[username] method=post> <input type=submit value="Send Mail"> </form></td><td> <form action=buds.php?game=$game&bud=$members[username] method=post> <input type=submit value="Add to Buddy List"> </form></td></tr></table></center> </td></tr></table> $closeHTML END; ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 What do you mean the age is at the top? Did you remove the "echo $userAge;?" Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 Brilliant!, thanks - that works Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 4, 2008 Share Posted November 4, 2008 MM -DD-YYYY in the databse, and upon registration - the format is MM DD YYYY OK, last attempt. It's your database and presumably you can view what's in it, not guess. Notice that you've clearly told us what format you're using for date. Notice that you've given us two different answers to that question. So, take a deep breath, take a careful look and tell us without reservation which it is - and please note that MM -DD-YYYY is not the same as MM-DD-YYYY. In case it isn't obvious yet, the best date format to use in your database is the MySQL date type - it uses the ISO standard (and absolutely unambiguous) YYYY-MM-DD form. You can easily perform all sorts of manipulations very simply once you have a real date in a real format. Just because the database format is different from how you might want to display dates should not affect your choice of a standard date field. Perhaps it is like thaty format upon registration and database and perhaps it somehow changes whilst the file is being executed? Extraordinarily unlikely. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 5, 2008 Author Share Posted November 5, 2008 MM -DD-YYYY in the databse, and upon registration - the format is MM DD YYYY OK, last attempt. It's your database and presumably you can view what's in it, not guess. Notice that you've clearly told us what format you're using for date. Notice that you've given us two different answers to that question. So, take a deep breath, take a careful look and tell us without reservation which it is - and please note that MM -DD-YYYY is not the same as MM-DD-YYYY. In case it isn't obvious yet, the best date format to use in your database is the MySQL date type - it uses the ISO standard (and absolutely unambiguous) YYYY-MM-DD form. You can easily perform all sorts of manipulations very simply once you have a real date in a real format. Just because the database format is different from how you might want to display dates should not affect your choice of a standard date field. Perhaps it is like thaty format upon registration and database and perhaps it somehow changes whilst the file is being executed? Extraordinarily unlikely. Thanks, but you may not be aware but F1 made the topic solved - so really there is no error left. Quote Link to comment 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.