![]() |
getAge() with wrong return - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: getAge() with wrong return (/showthread.php?tid=81214) |
getAge() with wrong return - sprhld - 02-04-2022 Hello! I have to check the age in my app and I use getAge() and get a wrong age. I'm in Germany, so I use German dates here: PHP Code: $bt2 = Time::parse($this->request->getVar('geburtstag')); The dates in "geburtstag" are 05.02.2008 and 03.02.2008. Today is the 04.02.2008. But both datas returns the same age 14. What do I not see here? RE: getAge() with wrong return - kenjis - 02-04-2022 See https://github.com/codeigniter4/CodeIgniter4/blob/ec146df8bcbdc50b126106ed5ebacc77bac369df/system/I18n/Time.php#L461-L468 It seems it considers only year. RE: getAge() with wrong return - kenjis - 02-05-2022 > Perfect for checking the age of someone based on their birthday: https://codeigniter4.github.io/userguide/libraries/time.html#getage How do you calculate the age of someone? RE: getAge() with wrong return - InsiteFX - 02-05-2022 @kenjis, If he is getting the users age should he not be using a date type method? RE: getAge() with wrong return - sprhld - 02-05-2022 (02-04-2022, 04:38 PM)kenjis Wrote: See https://github.com/codeigniter4/CodeIgniter4/blob/ec146df8bcbdc50b126106ed5ebacc77bac369df/system/I18n/Time.php#L461-L468 And that's maybe wrong, because it's not the age, it's just the year. (02-05-2022, 02:54 AM)InsiteFX Wrote: @kenjis, For me it is a little bit wired, if I have to work with time and date. So much different ways, some provided by PHP, some by CI. Now I upgrade an other helper, which I use to calculate date-time-diffs and it works correctly. It's actually very easy ;-) Do now wonder, it was designed to use this as my favorite diff-helper and it should to more as this helper do right now. PHP Code: function dateTimeDiff($older, $newer, $return = 'SEC') |