Created
February 20, 2015 14:47
-
-
Save dennisdegryse/467967ae248e1f544470 to your computer and use it in GitHub Desktop.
Transform datetime from dd-mm-yyyy to yyyy-mm-dd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/php | |
<?php | |
$db = new PDO('mysql:host=yourhost;dbname=yourdb;charset=utf8', 'yourusername', 'yourpassword'); | |
$stmt = $db->query("SELECT id, datum FROM yourtable"); | |
$records = []; | |
while ($obj = $stmt->fetchObject()) { | |
$records[$obj->id] = implode('-', array_reverse(explode('-', $obj->datum))); | |
} | |
foreach ($records as $id -> $date) { | |
$stmt = $db->prepare("UPDATE yourtable SET datum2=:date where id=:id"); | |
$stmt->bindParam(':id', $id, PDO::PARAM_INT); | |
$stmt->bindParam(':date', $date, PDO::PARAM_STR); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment