Skip to content

Instantly share code, notes, and snippets.

@codemaniac
Created June 27, 2012 17:25
Show Gist options
  • Save codemaniac/3005546 to your computer and use it in GitHub Desktop.
Save codemaniac/3005546 to your computer and use it in GitHub Desktop.
MySQL datetime to unix ticks in python
#!/usr/bin/python
# -*- coding: utf-8 -*-
from datetime import datetime
import time
def datetime2unixticks(ts):
ts = ts.split()[0]
dt = datetime.strptime(ts, '%Y-%m-%d')
return int(time.mktime(dt.timetuple()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment