Skip to content

Commit adc1409

Browse files
authored
add subsecond support to Now() (#242)
1 parent 5a630ba commit adc1409

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mssql/functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.db.models.expressions import Case, Exists, Expression, OrderBy, When, Window
1111
from django.db.models.fields import BinaryField, Field
1212
from django.db.models.functions import Cast, NthValue, MD5, SHA1, SHA224, SHA256, SHA384, SHA512
13+
from django.db.models.functions.datetime import Now
1314
from django.db.models.functions.math import ATan2, Ln, Log, Mod, Round, Degrees, Radians, Power
1415
from django.db.models.functions.text import Replace
1516
from django.db.models.lookups import In, Lookup
@@ -123,6 +124,10 @@ def sqlserver_exists(self, compiler, connection, template=None, **extra_context)
123124
sql = 'CASE WHEN {} THEN 1 ELSE 0 END'.format(sql)
124125
return sql, params
125126

127+
def sqlserver_now(self, compiler, connection, **extra_context):
128+
return self.as_sql(
129+
compiler, connection, template="SYSDATETIME()", **extra_context
130+
)
126131

127132
def sqlserver_lookup(self, compiler, connection):
128133
# MSSQL doesn't allow EXISTS() to be compared to another expression
@@ -456,6 +461,7 @@ def sqlserver_sha512(self, compiler, connection, **extra_context):
456461
Round.as_microsoft = sqlserver_round
457462
Window.as_microsoft = sqlserver_window
458463
Replace.as_microsoft = sqlserver_replace
464+
Now.as_microsoft = sqlserver_now
459465
MD5.as_microsoft = sqlserver_md5
460466
SHA1.as_microsoft = sqlserver_sha1
461467
SHA224.as_microsoft = sqlserver_sha224

0 commit comments

Comments
 (0)