Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created August 16, 2012 22:20
Show Gist options
  • Save ekka21/3374133 to your computer and use it in GitHub Desktop.
Save ekka21/3374133 to your computer and use it in GitHub Desktop.
sql: change varchar to DATE format without loosing any data in the column.
- add tmp column to have DATE format
ALTER TABLE requests
ADD tmp DATE;
/update Varchar format of mm/dd/yyyy
UPDATE requests
SET
tmp = STR_TO_DATE(date_due,'%m/%d/%Y');
//drop date_due column
ALTER TABLE requests
DROP date_due;
//change tmp col to date_due col
ALTER TABLE requests
CHANGE tmp date_due DATE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment