Skip to content

Instantly share code, notes, and snippets.

@mbylstra
Last active December 23, 2015 04:19
Show Gist options
  • Save mbylstra/6579686 to your computer and use it in GitHub Desktop.
Save mbylstra/6579686 to your computer and use it in GitHub Desktop.
convert a python date to a mysql date string
from django.db import connection
from django.db.backends.mysql.base import DatabaseOperations
def py_datetime_to_mysql(d):
db_ops = DatabaseOperations(connection)
return db_ops.value_to_db_datetime(d)
#eg:
from django.db import connection
py_datetime_to_mysql(datetime.now())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment