Skip to content

Instantly share code, notes, and snippets.

@JimHaughwout
Last active August 29, 2015 14:08
Show Gist options
  • Save JimHaughwout/caf7d4919c1995345b75 to your computer and use it in GitHub Desktop.
Save JimHaughwout/caf7d4919c1995345b75 to your computer and use it in GitHub Desktop.
Python Dates, Date-Time to Oracle
from datetime import date, datetime
def oracle_weekday(dt):
'''
Takes a python datetime or date object.
Returns Day of Week in Oracle model
Day python oracle
Mon 0 2
Tue 1 3
Wed 2 4
Thu 3 5
Fri 4 6
Sat 5 7
Sun 6 1
'''
try:
return (dt.weekday() + 2) % 8
except:
e = "oracle_weekday: Passed %r. Not a date or datetime object." % dt
raise ValueError(e)
def oracle_dow_to_py_dow(oracle_day_of_week):
try:
return (int(oracle_day_of_week) - 2) % 7
except:
e = "oracle_dow_to_py_dow: Passed %r. Not an int" % oracle_day_of_week
raise ValueError(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment