开发者

using django orm to realize my filter

开发者 https://www.devze.com 2023-03-20 13:51 出处:网络
My raw sql statement is as follows: select* from t where dateadd(ss,closeda开发者_运维知识库te-datediff(ss,getdate(),getutcdate()),\'1970-1-1\')

My raw sql statement is as follows:

select* from t 
where dateadd(ss,closeda开发者_运维知识库te-datediff(ss,getdate(),getutcdate()),'1970-1-1')
      between convert (datetime,'2011-7-1 00:00:00') and convert(datetime,'2011-7-31 23:59:59')

closedate is one of my column in table t ,it means:seconds from 1970-1-1.

HOW can i realize this query using Django ORM?,here involved dateadd,datediff(sql server 2005) APIs,

I dont know how to handler this prob.


Are you trying to do a date range query ? Something like, get all records which fall between 2 dates? If yes, then something like the following would give you the records in the last 30days

today = date.today() + timedelta(days=1)
n_days_ago = today + timedelta(days=-30)
trans = Transactions.objects.filter(payment_received_date__range=[n_days_ago ,today])
0

精彩评论

暂无评论...
验证码 换一张
取 消