Format a PHP Timestamp to Mysql Datetime/Timestamp

Useful when converting between those two formats often:

function formatDateMysql($timestamp = false) {
    if ($timestamp === false) {
        $timestamp = time();
    }
    return date('Y-m-d H:i:s', $timestamp);
}

in the other direction you can use the mighty strtotime function, o god I love PHP so much <3

(Yes Java, your Date object is a mess!)

Published by

KB

I'm a student at TUM in Computer Science & Pizza eating. Passionate for SRE, beautiful Code and Club Mate.