Convert PHP Unix timestamp to MySQL datetime / MySQL time to PHP time convert function

PHP uses Unix Timestamp. While MySQL uses datetime format (YYYY-MM-DD HH-MM-SS) to store times. So, I’ve wriiten to easy functions to convert php timestamp to mySQL datetime format or vice versa!

// Converts SQL time to PHP Time Format

function time_sql2php($sqltime){
    return strtotime($sqltime . " GMT");

// Converts PHP time format to SQL Time Format

function time_php2sql($unixtime){
    return gmdate("Y-m-d H:i:s", $unixtime);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s