Skip to content

Commit bca1c5f

Browse files
committed
improve date/time casting info
1 parent 3079006 commit bca1c5f

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

docs/basics/cmdline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ Set the start-of-week offset, where 0 is Saturday. The default is 2, i.e Monday.
464464
-z [0|1]
465465
```
466466

467-
Set the format for `"D"$` date parsing: 0 for mm/dd/yyyy and 1 for dd/mm/yyyy.
467+
Set the format for `"D"$` date parsing.
468468

469469
:fontawesome-solid-book-open:
470-
[`\z` system command](syscmds.md#z-date-parsing)
470+
[`\z` system command](syscmds.md#z-date-parsing) for detail
471471

472472

473473
[![](../img/xkcd.tar.png)](https://xkcd.com/1168/)

docs/basics/syscmds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ q)\x .z.pi / restore default
951951
\z 0|1
952952
```
953953

954-
Show or set the format for `"D"$` date parsing. `B` is 0 for mm/dd/yyyy and 1 for dd/mm/yyyy.
954+
Show or set the format for `"D"$` date parsing. `0` for mm/dd/yyyy and `1` for dd/mm/yyyy. Default value is `0`.
955955

956956
```q
957957
q)\z

docs/ref/cast.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,18 @@ q)"x"$"abc"
136136

137137
## Temporal
138138

139-
Find parts of time:
139+
The following symbols can be used to extract parts of a temporal type
140+
141+
* `year` to provide year as an integer
142+
* `month` to provide `month` datatype
143+
* `mm` to provide month as an integer, where January is 01i
144+
* `week` to provide a `date` datatype, presenting the week in which the temporal variable resides. The value returned is the start of the week (Monday). If the `date` represents a Monday, it is not altered.
145+
* `dd` to provide day as an integer, where 1st of the month is 1i
146+
* `hh` to provide hour as an integer
147+
* `uu` to provide minutes as an integer
148+
* `ss` to provide to seconds as an integer
149+
150+
For example:
140151

141152
```q
142153
q)`hh`uu`ss$03:55:58.11
@@ -145,6 +156,8 @@ q)`year`dd`mm`hh`uu`ss$2015.10.28D03:55:58
145156
2015 28 10 3 55 58i
146157
```
147158

159+
The following shows which information can be extracted from each temporal [datatype](../basics/datatypes.md)
160+
148161
```txt
149162
| year | month | mm | week | dd | hh | uu | ss
150163
--------------------------------------------------------
@@ -156,14 +169,8 @@ timespan | | | | | | x | x | x
156169
minute | | | | | | x | x | x
157170
second | | | | | | x | x | x
158171
time | | | | | | x | x | x
159-
160-
161-
milliseconds: "i"$time mod 1000
162-
milliseconds: "i"$mod[;1000]"t"$datetime
163-
nanoseconds: "i"$timestamp mod 1000000000
164172
```
165173

166-
167174
!!! detail "Casting to narrower temporal type truncates rather than rounds"
168175

169176
Such conversions use floor, because the day, hour, minute, second… are all [) notions. (What hour are we in; what millisecond are we in…)
@@ -172,6 +179,13 @@ nanoseconds: "i"$timestamp mod 1000000000
172179

173180
As a consequence `.z.t-.z.n` is typically negative.
174181

182+
Numeric calculations on the base numeric type can also be used to extract part of a temporal type, for the example using the [`mod`](mod.md) keyword
183+
184+
```q
185+
milliseconds: "i"$01:00:00.100 mod 1000 / extract milliseconds from time datatype
186+
milliseconds: "i"$mod[;1000]"t"$2000.01.01T12:00:00.500 / extract milliseconds from datetime datatype
187+
nanoseconds: "i"$2014.11.22D17:43:40.123456789 mod 1000000000 / extract nanoseconds from timestamp datatype
188+
```
175189

176190
## Identity
177191

docs/ref/tok.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ q)"PZ"$\:"20191122-11:11:11.123"
203203
[yy]yymmdd
204204
ddMMM[yy]yy
205205
yyyy/[mm|MMM]/dd
206-
[mm|MMM]/dd/[yy]yy / \z 0
207-
dd/[mm|MMM]/[yy]yy / \z 1
206+
[mm|MMM]/dd/[yy]yy / when \z is set to 0 (default)
207+
dd/[mm|MMM]/[yy]yy / when \z is set to 1
208208
```
209209

210210
:fontawesome-solid-book-open:

0 commit comments

Comments
 (0)