获取两个日期之间的记录 [英] Get the records between two dates

查看:99
本文介绍了获取两个日期之间的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Billing 的表,其中包含以下列

I have a table called Billing which contains the below columns

id| resource_name | start_date | end_date | total_amount

此表填充了具有不同开始日期和结束日期的不同资源的数据。我需要从表中检索数据。

This table is populated with data for different resource with different start_date and end_dates. I need to retrieve the data from the tables.

id| resource_name | start_date          | end_date            | total_amount
1 | abc           | 2018-09-15 03:00:00 | 2018-09-15 04:00:00 | 20

如果我这样写查询,它将返回上面的结果

If I write a query like this it will return the above result

select * from billing where start_date >= '2018-09-15 03:00:00' and end_date <= '2018-09-15 04:00:00'

但以下内容并非如此

select * from billing where start_date >= '2018-09-15 03:00:00' and end_date <= '2018-09-15 03:30:00'

是否有任何方法可以检索相同的内容。我正在使用Django ORM进行同样的操作

Is there any way to retrieve the same . I am using Django ORM to do the same

推荐答案

您可以使用django过滤器方法。

you can use the django filter method.

Billing.objects.filter(start_date__gte='2018-09-15 03:00:00', end_date__lte='2018-09-15 03:30:00')

这篇关于获取两个日期之间的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆