Hartley Posted July 30, 2007 Share Posted July 30, 2007 I'm having some problems reading this on the PHP site. I need to do the following and don't know how to achieve it: 1. Convert a birthday into a unix timestamp (mm-dd-yyyy) 2. Convert it back. Thanks in advance for any help you may be able to provide. Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted July 30, 2007 Share Posted July 30, 2007 try <?php $timestamp = strtotime($bday); // get unix timestamp, but im not sure of the date format?? worth a try $bday = date("m-d-Y", $timestamp); //convert it back Quote Link to comment Share on other sites More sharing options...
Hartley Posted July 30, 2007 Author Share Posted July 30, 2007 Fantastic, got it to work, however I came across another problem I should have foreseen: birthdays before 1970, which we have several of. A -1 won't do too well for us here =( Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted July 30, 2007 Share Posted July 30, 2007 if you date format is YYYY then it shouldn't matter. also unix timestamps just go backwards (into the negative) for 1970 hope that puts you at ease Quote Link to comment Share on other sites More sharing options...
Hartley Posted July 30, 2007 Author Share Posted July 30, 2007 I decided to take a different approach to this, and going to post the result: <?php while($row = mysql_fetch_assoc($fullquery)) { $user = "{$row['username']}"; $bday = "{$row['birthday']}"; list($month, $day, $year) = split('[/.-]', $bday); $date = date("m-d-Y"); list($monthnow, $daynow, $yearnow) = split('[/.-]', $date); $day1 = $daynow - $day; if ($day1 < 0) { $monthnow = $monthnow - 1; } else { $monthnow = $monthnow; } $month1 = $monthnow - $month; if ($month1 < 0) { $yearnow = $yearnow - 1; } else { $yearnow = $yearnow; } $age = $yearnow - $year; ?> This breaks down the current date and birthday, and does some math to each separate section. The math determines whether or not that date has passed yet this year. If it did pass, it will simply do the current year minus the old year. If it hasn't passed, it will take 1 off of the final result. 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.