0

We have date "30-DEC-99" in oracle database but when our code reads that date is reading like "datetime.datetime(1899, 12, 30, 0, 0)", why the year 99 is reading like 1899 rather 1999? how do I fix this issue? please suggest.

3
Contributors
3
Replies
57
Views
2 Years
Discussion Span
Last Post by Lardmeister
0

I don't know why it reads 1899. Here is a possible patch

>>> import datetime as dt
>>> def patch_datetime(x):
...   delta = x - dt.datetime(x.year, x.month, x.day)
...   s = "{:0>2}-{:0>2}-{:0>2}".format(x.day, x.month, x.year % 100)
...   d = dt.datetime.strptime(s, '%d-%m-%y')
...   return d + delta
... 
>>> x = dt.datetime(1899, 12, 30, 0, 0)
>>> x = patch_datetime(x)
>>> x
datetime.datetime(1999, 12, 30, 0, 0)
>>> y = dt.datetime(year = 2014, month=2, day = 5)
>>> y = patch_datetime(y)
>>> y
datetime.datetime(2014, 2, 5, 0, 0)

Edit: bugfix to include date and time.

Edited by Gribouillis

1

Note that there may be some more trouble if the database contains '29-FEB-00' because 2000 is a leap year, and not 1900.

Edited by Gribouillis

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.