django-pyodbc-azure icon indicating copy to clipboard operation
django-pyodbc-azure copied to clipboard

Bug when obtaining distinct years from date

Open tylerwmarrs opened this issue 8 years ago • 2 comments

It appears that the logic on this line causes problems with years that are only two digits. I know that this is a pretty uncommon case, however it is something to consider.

The logic on this line given a date in SQL Server as '0017-01-01' will cause that logic to error. Python's datetime library accepts two digit years, for example:

from datetime import datetime
datetime(17, 1, 1)

https://github.com/michiya/django-pyodbc-azure/blob/4df37f3ec40abaf1aca608e1922a93073db8f144/sql_server/pyodbc/operations.py#L192

The problem seems to be when you obtain the Year in the SQL it provides a 2 digit value. When casting back into a datetime it creates an invalid format of "17-01-01".

tylerwmarrs avatar Oct 12 '17 21:10 tylerwmarrs

image

tylerwmarrs avatar Oct 12 '17 21:10 tylerwmarrs

image

tylerwmarrs avatar Oct 12 '17 21:10 tylerwmarrs