WAMFT1 Posted June 13, 2016 Share Posted June 13, 2016 Hi all I was using the below code on our website to return current age and it works perfectly. Recently we had to change our web host and now this piece of code seems to be a casualty to the move. The page stops loading past this point. Can anyone suggest why or what I can use in its place? I liked that it was just one line. Easy. <?php $now=new DateTime(); $birthday=new DateTime($dob); $interval= $now->diff($birthday); echo $interval->format('%Y');?> Quote Link to comment https://forums.phpfreaks.com/topic/301338-age-code/ Share on other sites More sharing options...
Barand Posted June 13, 2016 Share Posted June 13, 2016 $age = (new DateTime($dob))->diff(new DateTime())->y; should work with PHP 5.3 or later. What is in $dob? Has the format that is being passed in $dob changed? Quote Link to comment https://forums.phpfreaks.com/topic/301338-age-code/#findComment-1533614 Share on other sites More sharing options...
WAMFT1 Posted June 14, 2016 Author Share Posted June 14, 2016 Thanks Barand, I have managed to get the original code working again. I checked the table structure after the move and nothing had changed there but I noticed that dates and time were not correct. I added a set timezone to the functions file and now everything seems to be working again. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/301338-age-code/#findComment-1533640 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.