Skip to content

Commit c8d7e56

Browse files
rakhi-prathapsimon-dew
authored andcommitted
[DOC-11152] Changes to date functions (#383)
1 parent 97ebbcc commit c8d7e56

File tree

1 file changed

+85
-19
lines changed

1 file changed

+85
-19
lines changed

modules/n1ql/pages/n1ql-language-reference/datefun.adoc

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,23 @@ If the date string does not explicitly declare the value of a component, then th
588588
* The month and day default to 1.
589589
* The century (when not specified by year) defaults to 19 if year is greater than or equal to 69, or 20 otherwise.
590590
* All other numeric components default to 0.
591-
* The time zone defaults to the local local system time zone.
591+
* The time zone defaults to the local system time zone.
592592
593593
In cases where the timezone is not specified, the local system time is assumed.
594594
595595
For example, `2016-02-07` is equivalent to `2016-02-07T00:00:00` and parsing just `16` as the year is equivalent to `2016-01-01T00:00:00` in the local system time zone.
596596
====
597597

598+
[NOTE#tzn-date-format]
599+
.TZN Date Format
600+
====
601+
In addition to the date formats listed <<date-string,here>>, {sqlpp} also supports the `TZN` (Time Zone Name) format.
602+
This format parses date strings in the same way as `TZD` but outputs the time zone name instead of the offset.
603+
For example, the `TZN` representation of the "Australia/Darwin" time zone is `ACST`.
604+
605+
For an example of its usage, refer to the <<ex-str-to-tz,STR_TO_TZ()>> function.
606+
====
607+
598608
[#manipulating-components]
599609
== Manipulating Date Components
600610

@@ -1302,7 +1312,7 @@ WHERE reviews[0].date BETWEEN "2013-01-01 %" AND "2014-01-01 %";
13021312
NOTE: When querying between two dates, you must specify the full date (with time and time zone) or use the wildcard character (%).
13031313

13041314
[#fn-date-format-str]
1305-
== DATE_FORMAT_STR(date1, fmt)
1315+
== DATE_FORMAT_STR(date1, [input-fmt,] fmt)
13061316

13071317
=== Description
13081318

@@ -1315,6 +1325,13 @@ A string, or any valid xref:n1ql-language-reference/index.adoc[expression] which
13151325
+
13161326
If this argument is not a valid date string then `null` is returned.
13171327

1328+
input-fmt::
1329+
The format of the input string, `date1`.
1330+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string.
1331+
+
1332+
*Optional argument*.
1333+
Only required if `date1` is not in a standard format or if the input and output formats are different.
1334+
13181335
fmt::
13191336
A string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string, representing a <<date-string,supported date format>> to output the result as.
13201337
+
@@ -1331,7 +1348,8 @@ A date string in the format specified.
13311348
----
13321349
SELECT DATE_FORMAT_STR('2016-05-15T00:00:23+00:00', '1111-11-11') as full_to_short,
13331350
DATE_FORMAT_STR('2016-05-15', '1111-11-11T00:00:00+00:00') as short_to_full,
1334-
DATE_FORMAT_STR('01:10:05', '1111-11-11T01:01:01Z') as time_to_full;
1351+
DATE_FORMAT_STR('01:10:05', '1111-11-11T01:01:01Z') as time_to_full,
1352+
DATE_FORMAT_STR('15-MAY-2016', 'DD-MON-YYYY', 'YYYY-MM-DD') as month_to_numeric;
13351353
----
13361354
13371355
.Results
@@ -1340,8 +1358,9 @@ SELECT DATE_FORMAT_STR('2016-05-15T00:00:23+00:00', '1111-11-11') as full_to_sho
13401358
[
13411359
{
13421360
"full_to_short": "2016-05-15",
1343-
"short_to_full": "2016-05-15T00:00:00-07:00",
1344-
"time_to_full": "0000-01-01T01:10:05-08:00"
1361+
"short_to_full": "2016-05-15T00:00:00Z",
1362+
"time_to_full": "0000-01-01T01:10:05Z",
1363+
"month_to_numeric": "2016-05-15"
13451364
}
13461365
]
13471366
----
@@ -1801,15 +1820,15 @@ SELECT DATE_TRUNC_MILLIS(1463284740000, 'day') as day,
18011820
[
18021821
{
18031822
"day": 1463270400000,
1804-
"month": 1462147200000,
1805-
"year": 1451696400000
1823+
"month": 1462060800000,
1824+
"year": 1451606400000
18061825
}
18071826
]
18081827
----
18091828
====
18101829

18111830
[#fn-date-trunc-str]
1812-
== DATE_TRUNC_STR(date1, part)
1831+
== DATE_TRUNC_STR(date1, part [,fmt])
18131832

18141833
=== Description
18151834

@@ -1829,6 +1848,13 @@ This function accepts the components `millennium`, `century`, `decade`, `year`,
18291848
+
18301849
If an invalid part is specified, then `null` is returned.
18311850

1851+
fmt::
1852+
The format of the input string, `date1`.
1853+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string.
1854+
+
1855+
*Optional argument*.
1856+
Only required if `date1` is not in a standard format.
1857+
18321858
=== Return Value
18331859

18341860
A date string representing the truncated date.
@@ -1840,7 +1866,8 @@ A date string representing the truncated date.
18401866
----
18411867
SELECT DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'day') as day,
18421868
DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'month') as month,
1843-
DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'year') as year;
1869+
DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'year') as year,
1870+
DATE_TRUNC_STR('05/18/2016 03:59:00', 'month', 'MM/DD/YYYY HH24:MI:SS') as month_custom;
18441871
----
18451872
18461873
.Results
@@ -1850,7 +1877,8 @@ SELECT DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'day') as day,
18501877
{
18511878
"day": "2016-05-18T00:00:00Z",
18521879
"month": "2016-05-01T00:00:00Z",
1853-
"year": "2016-01-01T00:00:00Z"
1880+
"year": "2016-01-01T00:00:00Z",
1881+
"month_custom": "05/01/2016 00:00:00"
18541882
}
18551883
]
18561884
----
@@ -2596,12 +2624,13 @@ AS Milliseconds;
25962624
====
25972625

25982626
[#fn-date-str-to-utc]
2599-
== STR_TO_UTC(date1)
2627+
== STR_TO_UTC(date1 [, [input-fmt,] fmt])
26002628

26012629
=== Description
26022630

26032631
Converts a date string into the equivalent date in UTC.
2604-
The output date format follows the date format of the date passed as input.
2632+
By default, the output date format follows the date format of the date passed as input.
2633+
However, you can specify a different output format if needed.
26052634

26062635
=== Arguments
26072636

@@ -2611,6 +2640,20 @@ This is the date to convert to UTC.
26112640
+
26122641
If this argument is not a valid date format, then `null` is returned.
26132642

2643+
input-fmt::
2644+
The format of the input string, `date1`.
2645+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string.
2646+
+
2647+
*Optional argument*.
2648+
Only required if `date1` is not in a standard format or if the input and output formats are different.
2649+
2650+
fmt::
2651+
The format of the resulting UTC date.
2652+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string, and must be a <<date-string,supported date format>>.
2653+
+
2654+
*Optional argument*.
2655+
If not specified, the output date format follows the date format of the input string, `date1`.
2656+
26142657
=== Return Value
26152658

26162659
A single date string representing the date string converted to UTC.
@@ -2621,7 +2664,8 @@ A single date string representing the date string converted to UTC.
26212664
[source,sqlpp]
26222665
----
26232666
SELECT STR_TO_UTC('1111-11-11T00:00:00+08:00') as full_date,
2624-
STR_TO_UTC('1111-11-11') as short_date;
2667+
STR_TO_UTC('1111-11-11') as short_date,
2668+
STR_TO_UTC('1111-11-11', 'YYYY-MM-DD', 'YYYY-MM-DD HH:MI:SS') as utc_date;
26252669
----
26262670
26272671
.Results
@@ -2630,19 +2674,21 @@ STR_TO_UTC('1111-11-11') as short_date;
26302674
[
26312675
{
26322676
"full_date": "1111-11-10T16:00:00Z",
2633-
"short_date": "1111-11-11"
2677+
"short_date": "1111-11-11",
2678+
"utc_date": "1111-11-11 12:00:00"
26342679
}
26352680
]
26362681
----
26372682
====
26382683

26392684
[#fn-date-str-to-tz]
2640-
== STR_TO_TZ(date1, tz)
2685+
== STR_TO_TZ(date1, tz [, [input-fmt,] fmt])
26412686

26422687
=== Description
26432688

26442689
Converts a date string to its equivalent in the specified timezone.
2645-
The output date format follows the date format of the date passed as input.
2690+
By default, the output date format follows the date format of the date passed as input.
2691+
However, you can specify a different output format if needed.
26462692

26472693
=== Arguments
26482694

@@ -2657,28 +2703,48 @@ A string, or any valid xref:n1ql-language-reference/index.adoc[expression] which
26572703
+
26582704
If this argument is not a valid timezone, then `null` is returned.
26592705

2706+
input-fmt::
2707+
The format of the input string, `date1`.
2708+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string.
2709+
+
2710+
*Optional argument*.
2711+
Only required if `date1` is not in a standard format or if the input and output formats are different.
2712+
2713+
fmt::
2714+
The format of the output date.
2715+
This can be a string, or any valid xref:n1ql-language-reference/index.adoc[expression] which evaluates to a string, and must be a <<date-string,supported date format>>.
2716+
+
2717+
*Optional argument*.
2718+
If not specified, the output date format follows the date format of the input string, `date1`.
2719+
26602720
=== Return Value
26612721

26622722
A single date string representing the date string converted to the specified timezone.
26632723

2724+
[[ex-str-to-tz]]
26642725
=== Examples
26652726

26662727
====
26672728
[source,sqlpp]
26682729
----
26692730
SELECT STR_TO_TZ('1111-11-11T00:00:00+08:00', 'America/New_York') as est,
26702731
STR_TO_TZ('1111-11-11T00:00:00+08:00', 'UTC') as utc,
2671-
STR_TO_TZ('1111-11-11', 'UTC') as utc_short;
2732+
STR_TO_TZ('1111-11-11', 'UTC') as utc_short,
2733+
STR_TO_TZ('1111-11-11', 'UTC', 'YYYY-MM-DD', 'YYYY-MM-DD HH:MI:SS') as utc_datetime,
2734+
STR_TO_TZ('1111-11-11T00:00:00+07:00', 'Europe/Paris',
2735+
"YYYY-MM-DDThh:mm:ssTZD", "YYYY-MM-DDThh:mm:ssTZN") as tzn;
26722736
----
26732737
26742738
.Results
26752739
[source,json]
26762740
----
26772741
[
26782742
{
2679-
"est": "1111-11-10T11:00:00-05:00",
2743+
"est": "1111-11-10T11:03:58-04:56",
26802744
"utc": "1111-11-10T16:00:00Z",
2681-
"utc_short": "1111-11-11"
2745+
"utc_short": "1111-11-11",
2746+
"utc_datetime": "1111-11-11 12:00:00",
2747+
"tzn": "1111-11-10T17:09:21LMT"
26822748
}
26832749
]
26842750
----

0 commit comments

Comments
 (0)