summaryrefslogtreecommitdiffstats
path: root/Doc/includes/sqlite3/adapter_datetime.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/includes/sqlite3/adapter_datetime.py')
-rw-r--r--Doc/includes/sqlite3/adapter_datetime.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Doc/includes/sqlite3/adapter_datetime.py b/Doc/includes/sqlite3/adapter_datetime.py
new file mode 100644
index 0000000..3460498
--- /dev/null
+++ b/Doc/includes/sqlite3/adapter_datetime.py
@@ -0,0 +1,14 @@
+import sqlite3
+import datetime, time
+
+def adapt_datetime(ts):
+ return time.mktime(ts.timetuple())
+
+sqlite3.register_adapter(datetime.datetime, adapt_datetime)
+
+con = sqlite3.connect(":memory:")
+cur = con.cursor()
+
+now = datetime.datetime.now()
+cur.execute("select ?", (now,))
+print cur.fetchone()[0]