Welcome Guest, Not a member yet? Register   Sign In
PostgreSQL age function
#1

[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!




Theme © iAndrew 2016 - Forum software by © MyBB