时间:2021-07-01 10:21:17 帮助过:13人阅读
True
, datetime fields are converted to the current time zone before filtering. This requires time zone definitions in the database.
SQL equivalent:
1 2 |
SELECT ... WHERE EXTRACT( ‘month‘ FROM pub_date) = ‘12‘ ;
SELECT ... WHERE EXTRACT( ‘month‘ FROM pub_date) >= ‘6‘ ;
|
day
For date and datetime fields, an exact day match. Allows chaining additional field lookups. Takes an integer day.
1 2 |
Entry.objects.filter(pub_date__day=3)
Entry.objects.filter(pub_date__day__gte=3)
|
SQL equivalent:
1 2 |
SELECT ... WHERE EXTRACT( ‘day‘ FROM pub_date) = ‘3‘ ;
SELECT ... WHERE EXTRACT( ‘day‘ FROM pub_date) >= ‘3‘ ;
|
week
For date and datetime fields, return the week number (1-52 or 53) according to ISO-8601, i.e., weeks start on a Monday and the first week contains the year’s first Thursday.
Example:
1 2 |
Entry.objects. filter (pub_date__week = 52 )
Entry.objects. filter (pub_date__week__gte = 32 , pub_date__week__lte = 38 )
|
week_day
For date and datetime fields, a ‘day of the week’ match. Allows chaining additional field lookups.
Takes an integer value representing the day of week from 1 (Sunday) to 7 (Saturday).
Example:
1 2 |
Entry.objects.filter(pub_date__week_day=2)
Entry.objects.filter(pub_date__week_day__gte=2)
|
hour
For datetime and time fields, an exact hour match. Allows chaining additional field lookups. Takes an integer between 0 and 23.
Example:
1 2 3 |
Event.objects. filter (timestamp__hour = 23 )
Event.objects. filter (time__hour = 5 )
Event.objects. filter (timestamp__hour__gte = 12 )
|
SQL equivalent:
1 2 3 |
SELECT ... WHERE EXTRACT( ‘hour‘ FROM timestamp ) = ‘23‘ ;
SELECT ... WHERE EXTRACT( ‘hour‘ FROM time ) = ‘5‘ ;
SELECT ... WHERE EXTRACT( ‘hour‘ FROM timestamp ) >= ‘12‘ ;同
|
同时,还支持mintue,second
1 2 3 4 |
Event.objects.filter(time__minute=46)
Event.objects.filter(timestamp__second=31)
|
Django_数据库增删改查——查
标签:ocs mint Requires lis pad for enc mamicode warning