Welcome Guest, Not a member yet? Register   Sign In
getAge() with wrong return
#5

(02-04-2022, 04:38 PM)kenjis Wrote: See https://github.com/codeigniter4/CodeIgni...#L461-L468

It seems it considers only year.

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,

If he is getting the users age should he not be using a date type method?

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')
{
    $date = new DateTime($older);
    $now  = new DateTime($newer);

    $diff 0;

    switch ($return)
    {
        case ('SEC'):
        {
            $hourMulti 60;
            $dayMulti  1440;

            // Minutes
            $diff $diff $date->diff($now)->s;

            // Hours
            $diff $diff $date->diff($now)->$hourMulti;

            // Days
            $diff $diff $date->diff($now)->days $dayMulti;
            
            
break;
        }
        
        
case ('YEAR'):
        {
            $diff $date->diff($now);
            
            
break;
        }
    }

    return $diff;

Reply


Messages In This Thread
getAge() with wrong return - by sprhld - 02-04-2022, 11:22 AM
RE: getAge() with wrong return - by kenjis - 02-04-2022, 04:38 PM
RE: getAge() with wrong return - by kenjis - 02-05-2022, 12:54 AM
RE: getAge() with wrong return - by InsiteFX - 02-05-2022, 02:54 AM
RE: getAge() with wrong return - by sprhld - 02-05-2022, 04:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB