Skip to content

Commit 1827555

Browse files
maikhanhbuimShan0
andauthored
convert to DateField (#290)
Co-authored-by: mShan0 <[email protected]>
1 parent d51e40a commit 1827555

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mssql/operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def date_trunc_sql(self, lookup_type, sql, params, tzname=None):
178178

179179
# Python formats year with leading zeroes. This preserves that format for
180180
# compatibility with SQL Server's date since DATEPART drops the leading zeroes.
181-
CONVERT_YEAR = 'CONVERT(varchar(4), %s)' % sql
181+
CONVERT_YEAR = 'CONVERT(varchar(4), CONVERT(date, %s))' % sql
182182
CONVERT_QUARTER = 'CONVERT(varchar, 1+((DATEPART(quarter, %s)-1)*3))' % sql
183183
CONVERT_MONTH = 'CONVERT(varchar, DATEPART(month, %s))' % sql
184184
CONVERT_WEEK = "DATEADD(DAY, (DATEPART(weekday, %s) + 5) %%%% 7 * -1, %s)" % (sql, sql)

0 commit comments

Comments
 (0)