MySQL. Script to Convert Old Dates to New

If you have a table that contains a mix of date formats, here is a PHP script that will convert the old deprecated MySQL date formats to the new ones.

MySQL. Script to Convert Old Dates to New

This PHP script will convert the old deprecated MySQL date formats to the new ones.

$file_in = 'prod_20191222.sql';

$file_out = $file_in.'.converted.sql';

 

$replacements = [

    "ENGINE = MyISAM"=>"ENGINE = InnoDB",

    " NOT NULL DEFAULT '0000-00-00 00:00:00'"=>" DEFAULT NULL",

    "'0000-00-00 00:00:00'"=>"NULL",

    " NOT NULL DEFAULT '0000-00-00'"=>" DEFAULT NULL",

    "'0000-00-00'"=>"NULL",

];

 

$contents = file_get_contents($file_in);

foreach($replacements as $key=>$value) {

    $contents = str_replace($key, $value, $contents);

}

file_put_contents($file_out, $contents);

Previous
Serverless (Cloud Function) Providers Comparison
Next
Tiny Config Function in Dot Notation

Keep Reading

Explore more articles and insights

Ork: SSH Server Automation in Go

Ork: SSH Server Automation in Go

Read Article
Deno Deploy Killed My Start Page

Deno Deploy Killed My Start Page

Read Article
Back to Golang: Why I Switched From Static to Dynamic Again

Back to Golang: Why I Switched From Static to Dynamic Again

Read Article
View All Blog Posts