hi i have a large MySQL database (3000 records)- and the date fields are in the format YYYY-MM-DD, how can i change the to format to DD-MM-YYYY ? i don't want to have to change all 3000 records manually to the new format!
I would do a php query like this <?php $sql = "select datefield from tablename"; $rs = mysql_query($sql); while($row=@mysql_fetch_object($rs)) { $date = strtotime($row->timerow); $newdate = date("d-m-Y"); $qry = "update tablename set datefield = '$newdate' where id = '$row->id'"; $r = mysql_query($qry); } ?> cheers!
I don't know why you want to do that but running this one SQL query should fix it: UPDATE tableName SET dateField = CONCAT_WS('-', SUBSTRING(dateField, -2), SUBSTRING(dateField, 5, 2), SUBSTRING(dateField, 0, 4)); Code (markup):