mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.11.x] Refs #25240 -- Added ExtractWeek examples.
Backport of 085c2f94ec from master
			
			
This commit is contained in:
		| @@ -407,7 +407,7 @@ that deal with date-parts can be used with ``DateField``:: | ||||
|     >>> from datetime import datetime | ||||
|     >>> from django.utils import timezone | ||||
|     >>> from django.db.models.functions import ( | ||||
|     ...    ExtractYear, ExtractMonth, ExtractDay, ExtractWeekDay | ||||
|     ...     ExtractDay, ExtractMonth, ExtractWeek, ExtractWeekDay, ExtractYear, | ||||
|     ... ) | ||||
|     >>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=timezone.utc) | ||||
|     >>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=timezone.utc) | ||||
| @@ -417,12 +417,13 @@ that deal with date-parts can be used with ``DateField``:: | ||||
|     >>> Experiment.objects.annotate( | ||||
|     ...     year=ExtractYear('start_date'), | ||||
|     ...     month=ExtractMonth('start_date'), | ||||
|     ...     week=ExtractWeek('start_date'), | ||||
|     ...     day=ExtractDay('start_date'), | ||||
|     ...     weekday=ExtractWeekDay('start_date'), | ||||
|     ... ).values('year', 'month', 'day', 'weekday').get( | ||||
|     ... ).values('year', 'month', 'week', 'day', 'weekday').get( | ||||
|     ...     end_date__year=ExtractYear('start_date'), | ||||
|     ... ) | ||||
|     {'year': 2015, 'month': 6, 'day': 15, 'weekday': 2} | ||||
|     {'year': 2015, 'month': 6, 'week': 25, 'day': 15, 'weekday': 2} | ||||
|  | ||||
| ``DateTimeField`` extracts | ||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||
| @@ -451,8 +452,8 @@ Each class is also a ``Transform`` registered on ``DateTimeField`` as | ||||
|     >>> from datetime import datetime | ||||
|     >>> from django.utils import timezone | ||||
|     >>> from django.db.models.functions import ( | ||||
|     ...    ExtractYear, ExtractMonth, ExtractDay, ExtractWeekDay, | ||||
|     ...    ExtractHour, ExtractMinute, ExtractSecond, | ||||
|     ...     ExtractDay, ExtractHour, ExtractMinute, ExtractMonth, ExtractSecond, | ||||
|     ...     ExtractWeek, ExtractWeekDay, ExtractYear, | ||||
|     ... ) | ||||
|     >>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=timezone.utc) | ||||
|     >>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=timezone.utc) | ||||
| @@ -462,15 +463,17 @@ Each class is also a ``Transform`` registered on ``DateTimeField`` as | ||||
|     >>> Experiment.objects.annotate( | ||||
|     ...     year=ExtractYear('start_datetime'), | ||||
|     ...     month=ExtractMonth('start_datetime'), | ||||
|     ...     week=ExtractWeek('start_datetime'), | ||||
|     ...     day=ExtractDay('start_datetime'), | ||||
|     ...     weekday=ExtractWeekDay('start_datetime'), | ||||
|     ...     hour=ExtractHour('start_datetime'), | ||||
|     ...     minute=ExtractMinute('start_datetime'), | ||||
|     ...     second=ExtractSecond('start_datetime'), | ||||
|     ... ).values( | ||||
|     ...     'year', 'month', 'day', 'weekday', 'hour', 'minute', 'second', | ||||
|     ...     'year', 'month', 'week', 'day', 'weekday', 'hour', 'minute', 'second', | ||||
|     ... ).get(end_datetime__year=ExtractYear('start_datetime')) | ||||
|     {'year': 2015, 'month': 6, 'day': 15, 'weekday': 2, 'hour': 23, 'minute': 30, 'second': 1} | ||||
|     {'year': 2015, 'month': 6, 'week': 25, 'day': 15, 'weekday': 2, 'hour': 23, | ||||
|      'minute': 30, 'second': 1} | ||||
|  | ||||
| When :setting:`USE_TZ` is ``True`` then datetimes are stored in the database | ||||
| in UTC. If a different timezone is active in Django, the datetime is converted | ||||
|   | ||||
		Reference in New Issue
	
	Block a user