~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/functions/extract_date.rst

  • Committer: Andrew Hutchings
  • Date: 2011-02-15 22:03:42 UTC
  • mto: (2172.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2173.
  • Revision ID: andrew@linuxjedi.co.uk-20110215220342-k4tveraug3bpy2v5
Make fixes to temporal docs
Make a few minor docs cleanups/fixes
Start using syntax-highlighting code blocks

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
The following field names are available:
15
15
 
16
 
**day** ::
 
16
**day**
 
17
 
 
18
.. code-block:: mysql
17
19
        
18
20
        SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40');
19
21
 
21
23
 
22
24
*Result: 16*
23
25
 
24
 
**decade** ::
 
26
**decade**
 
27
 
 
28
.. code-block:: mysql
25
29
        
26
30
        SELECT EXTRACT(DECADE FROM TIMESTAMP '2001-02-16 20:38:40');
27
31
 
29
33
 
30
34
*Result: 200*
31
35
 
32
 
**dow** ::
 
36
**dow**
 
37
 
 
38
.. code-block:: mysql
33
39
        
34
40
        SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16 20:38:40');
35
41
 
37
43
 
38
44
*Result: 5*
39
45
 
40
 
**doy** ::
 
46
**doy**
 
47
 
 
48
.. code-block:: mysql
41
49
 
42
50
        SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
43
51
 
45
53
 
46
54
*Result: 47*
47
55
 
48
 
**hour** ::
 
56
**hour**
 
57
 
 
58
.. code-block:: mysql
49
59
 
50
60
        SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40');
51
61
 
53
63
 
54
64
*Result: 20*
55
65
 
56
 
**microseconds** ::
 
66
**microseconds**
 
67
 
 
68
.. code-block:: mysql
57
69
 
58
70
        SELECT EXTRACT(MICROSECONDS FROM TIME '17:12:28.5');
59
71
 
61
73
 
62
74
*Result: 28500000*
63
75
 
64
 
**minute** ::
 
76
**minute**
 
77
 
 
78
.. code-block:: mysql
65
79
 
66
80
        SELECT EXTRACT(MINUTE FROM TIMESTAMP '2001-02-16 20:38:40');
67
81
 
72
86
**month**
73
87
 
74
88
For timestamp values, the number of the month within the year (1 - 12). 
75
 
For interval values, the number of months (0 - 11). ::
 
89
For interval values, the number of months (0 - 11).
 
90
 
 
91
.. code-block:: mysql
76
92
 
77
93
        SELECT EXTRACT(MONTH FROM TIMESTAMP '2010-12-29 08:45:27');
78
94
 
79
 
*Result: 12* ::
 
95
*Result: 12*
 
96
 
 
97
.. code-block:: mysql
80
98
 
81
99
        SELECT EXTRACT(MONTH FROM INTERVAL '3 years 4 months');
82
100
 
83
 
*Result: 4* ::
 
101
*Result: 4*
 
102
 
 
103
.. code-block:: mysql
84
104
 
85
105
        SELECT EXTRACT(MONTH FROM INTERVAL '3 years 13 months');
86
106
 
87
107
*Result: 1*
88
108
 
89
 
**quarter** ::
 
109
**quarter**
 
110
 
 
111
.. code-block:: mysql
90
112
 
91
113
        SELECT EXTRACT(QUARTER FROM TIMESTAMP '2010-12-29 08:45:27');
92
114
 
94
116
        
95
117
*Result: 4*
96
118
 
97
 
**second** ::
 
119
**second**
 
120
 
 
121
.. code-block:: mysql
98
122
 
99
123
        SELECT EXTRACT(SECOND FROM TIMESTAMP '2010-12-29 08:45:27');
100
124
 
101
125
The seconds field, including fractional parts (0 - 59)
102
126
        
103
 
*Result: 27* ::
 
127
*Result: 27*
 
128
 
 
129
.. code-block:: mysql
104
130
 
105
131
        SELECT EXTRACT(SECOND FROM TIME '08:15:22.5');
106
132
 
116
142
 
117
143
ISO 8601:1988 means that if the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1. The ISO-8601 week starts on Monday.
118
144
 
119
 
It's possible for early January dates to be part of the 52nd or 53rd week of the previous year. For example, 2011-01-01 was part of the 52nd week of year 2010. ::
 
145
It's possible for early January dates to be part of the 52nd or 53rd week of the previous year. For example, 2011-01-01 was part of the 52nd week of year 2010.
 
146
 
 
147
.. code-block:: mysql
120
148
 
121
149
        SELECT EXTRACT(WEEK FROM TIMESTAMP '2010-01-25 12:44:06');
122
150
 
123
151
*Result: 4*
124
152
 
125
 
**year** ::
 
153
**year**
 
154
 
 
155
.. code-block:: mysql
126
156
 
127
157
        SELECT EXTRACT(YEAR FROM TIMESTAMP '2009-02-16 20:38:40');
128
158
 
129
159
*Result: 2009*
130
160
 
131
 
The valid field names for date_part are the same as for extract. ::
 
161
The valid field names for date_part are the same as for extract.
 
162
 
 
163
.. code-block:: mysql
132
164
 
133
165
        SELECT date_part('day', TIMESTAMP '2010-07-16 10:12:05');
134
166
 
135
 
*Result: 16* ::
 
167
*Result: 16*
 
168
 
 
169
.. code-block:: mysql
136
170
 
137
171
        SELECT date_part('hour', INTERVAL '5 hours 12 minutes');
138
172