Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mssql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def handle_datetimeoffset(dto_value):
# Decode bytes returned from SQL Server
# source: https://github.com/mkleehammer/pyodbc/wiki/Using-an-Output-Converter-function
tup = struct.unpack("<6hI2h", dto_value) # e.g., (2017, 3, 16, 10, 35, 18, 500000000)
return datetime.datetime(tup[0], tup[1], tup[2], tup[3], tup[4], tup[5], tup[6] // 1000)
return datetime.datetime(tup[0], tup[1], tup[2], tup[3], tup[4], tup[5], tup[6] // 1000,
datetime.timezone(datetime.timedelta(hours=tup[7], minutes=tup[8])))


class DatabaseWrapper(BaseDatabaseWrapper):
Expand Down
8 changes: 5 additions & 3 deletions mssql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ def sqlserver_exists(self, compiler, connection, template=None, **extra_context)
return sql, params

def sqlserver_now(self, compiler, connection, **extra_context):
return self.as_sql(
compiler, connection, template="SYSDATETIME()", **extra_context
)
if settings.USE_TZ:
return self.as_sql(compiler, connection, template="SYSDATETIMEOFFSET()", **extra_context)
else:
# continue using SYSDATETIME to get the DB local time when django is not TZ aware
return self.as_sql(compiler, connection, template="SYSDATETIME()", **extra_context)

def sqlserver_lookup(self, compiler, connection):
# MSSQL doesn't allow EXISTS() to be compared to another expression
Expand Down