Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robjbrain/0c8e43d6c29aac534579a9684fa95051 to your computer and use it in GitHub Desktop.
Save robjbrain/0c8e43d6c29aac534579a9684fa95051 to your computer and use it in GitHub Desktop.
How to set datetime to null when accidentally set to '0000-00-00 00:00:00'
# If you've accidentally got '0000-00-00 00:00:00' in a datetime field you can't fix it with this:
UPDATE table SET datetime = NULL WHERE datetime = '0000-00-00 00:00:00'
# Because you'll get this error:
Incorrect datetime value: '0000-00-00 00:00:00'
# But you can fix it with this
UPDATE table SET datetime = NULL WHERE datetime = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment