CodeIgniter Forums
PostgreSQL age function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: PostgreSQL age function (/showthread.php?tid=14554)



PostgreSQL age function - El Forum - 01-06-2009

[eluser]ReGeDa[/eluser]
Hello!
I use PostgreSQL as my database storage. I call function pg_age_to_array (look follow) for parsing the age result.
Code:
function pg_age_to_array($age) {
    if (preg_match('/^((\d+) year[s]? )?((\d+) mon[s]? )?((\d+) day[s]? )?(\d{2}):(\d{2}):(\d{2})\.\d+$/',$age,$matches)) {
        return array(
            'year' => $matches[2],
            'mon' => $matches[4],
            'day' => $matches[6],
            'hour' => $matches[7],
            'min' => $matches[8],
            'sec' => $matches[9]
        );
    }
    return FALSE;
}
Good luck!