talmik Posted July 10, 2018 Share Posted July 10, 2018 Hello all This bit of code is supposed to count the number of years between a creation date and the current date then place that number of years in the database. I seem to be missing something or have done something wrong. Can anyone see where it all went wrong? Quote function GetMemberYears($P_CharacterID) { $Creation = SQL_ReadField("Characters",$P_CharacterID,"CreationDate"); $CreationExpand = explode("/",$Creation); $curMonth = date("m"); $Years = date("y") - $CreationExpand[2]; if($curMonth<$CreationExpand[1] || ($curMonth==$CreationExpand[1] && date("d")<$CreationExpand[0])) $Years--; return $Years; } Link to comment Share on other sites More sharing options...
Barand Posted July 10, 2018 Share Posted July 10, 2018 Do it the easy way $theDate = '10/08/2005'; $dt1 = DateTime::createFromFormat('d/m/Y', $theDate); $years = $dt1->diff(new dateTime())->y; echo $years; //--> 12 Link to comment Share on other sites More sharing options...
requinix Posted July 10, 2018 Share Posted July 10, 2018 I sure hope you're not 18 years late to the Y2K party. Link to comment Share on other sites More sharing options...
Barand Posted July 10, 2018 Share Posted July 10, 2018 I wonder if there will be the same amount of panic when the Unix Epoch ends in the 2030's Link to comment Share on other sites More sharing options...
requinix Posted July 10, 2018 Share Posted July 10, 2018 Y2K38? Surely everything important is on 64-bit (or higher?) computers by then... Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted July 10, 2018 Share Posted July 10, 2018 I have 64 bit computer but I failed a y2k38 test returned a date in 1969 lol, guess I'll be finding solution to this. Of course it is using $date = '2040-02-01'; $format = 'l d F Y H:i'; $mydate1 = strtotime($date); echo '<p>', date($format, $mydate1), '</p>'; but when I use $date = '2040-02-01'; $format = 'l j F Y H:i'; $mydate2 = new DateTime($date); echo '<p>', $mydate2->format($format), '</p>'; I get my expected future date Link to comment Share on other sites More sharing options...
requinix Posted July 11, 2018 Share Posted July 11, 2018 Your computer may be 64-bit but what about your PHP? The first example will work with 64-bit PHP. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.