#NEWLINE# def date_trunc_sql( self , lookup_type , field_name ) : #NEWLINE# #INDENT# fields = [ 'year' , 'month' , 'day' , 'hour' , 'minute' , 'second' ] #NEWLINE# format = ( '%%Y-' , '%%m' , '-%%d' , ' %%H:' , '%%i' , ':%%s' ) #NEWLINE# format_def = ( '0000-' , '01' , '-01' , ' 00:' , '00' , ':00' ) #NEWLINE# try : #NEWLINE# #INDENT# i = ( fields . index ( lookup_type ) + 1 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# sql = field_name #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# format_str = '' . join ( ( [ f for f in format [ : i ] ] + [ f for f in format_def [ i : ] ] ) ) #NEWLINE# sql = ( "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % ( i , format_str ) ) #NEWLINE# #UNINDENT# return sql