You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/n1ql/pages/n1ql-language-reference/datefun.adoc
+85-19Lines changed: 85 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -588,13 +588,23 @@ If the date string does not explicitly declare the value of a component, then th
588
588
* The month and day default to 1.
589
589
* The century (when not specified by year) defaults to 19 if year is greater than or equal to 69, or 20 otherwise.
590
590
* 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.
592
592
593
593
In cases where the timezone is not specified, the local system time is assumed.
594
594
595
595
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.
596
596
====
597
597
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
+
598
608
[#manipulating-components]
599
609
== Manipulating Date Components
600
610
@@ -1302,7 +1312,7 @@ WHERE reviews[0].date BETWEEN "2013-01-01 %" AND "2014-01-01 %";
1302
1312
NOTE: When querying between two dates, you must specify the full date (with time and time zone) or use the wildcard character (%).
1303
1313
1304
1314
[#fn-date-format-str]
1305
-
== DATE_FORMAT_STR(date1, fmt)
1315
+
== DATE_FORMAT_STR(date1, [input-fmt,] fmt)
1306
1316
1307
1317
=== Description
1308
1318
@@ -1315,6 +1325,13 @@ A string, or any valid xref:n1ql-language-reference/index.adoc[expression] which
1315
1325
+
1316
1326
If this argument is not a valid date string then `null` is returned.
1317
1327
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
+
1318
1335
fmt::
1319
1336
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.
1320
1337
+
@@ -1331,7 +1348,8 @@ A date string in the format specified.
1331
1348
----
1332
1349
SELECT DATE_FORMAT_STR('2016-05-15T00:00:23+00:00', '1111-11-11') as full_to_short,
1333
1350
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;
1335
1353
----
1336
1354
1337
1355
.Results
@@ -1340,8 +1358,9 @@ SELECT DATE_FORMAT_STR('2016-05-15T00:00:23+00:00', '1111-11-11') as full_to_sho
1340
1358
[
1341
1359
{
1342
1360
"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"
1345
1364
}
1346
1365
]
1347
1366
----
@@ -1801,15 +1820,15 @@ SELECT DATE_TRUNC_MILLIS(1463284740000, 'day') as day,
1801
1820
[
1802
1821
{
1803
1822
"day": 1463270400000,
1804
-
"month": 1462147200000,
1805
-
"year": 1451696400000
1823
+
"month": 1462060800000,
1824
+
"year": 1451606400000
1806
1825
}
1807
1826
]
1808
1827
----
1809
1828
====
1810
1829
1811
1830
[#fn-date-trunc-str]
1812
-
== DATE_TRUNC_STR(date1, part)
1831
+
== DATE_TRUNC_STR(date1, part [,fmt])
1813
1832
1814
1833
=== Description
1815
1834
@@ -1829,6 +1848,13 @@ This function accepts the components `millennium`, `century`, `decade`, `year`,
1829
1848
+
1830
1849
If an invalid part is specified, then `null` is returned.
1831
1850
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
+
1832
1858
=== Return Value
1833
1859
1834
1860
A date string representing the truncated date.
@@ -1840,7 +1866,8 @@ A date string representing the truncated date.
1840
1866
----
1841
1867
SELECT DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'day') as day,
1842
1868
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;
1844
1871
----
1845
1872
1846
1873
.Results
@@ -1850,7 +1877,8 @@ SELECT DATE_TRUNC_STR('2016-05-18T03:59:00Z', 'day') as day,
1850
1877
{
1851
1878
"day": "2016-05-18T00:00:00Z",
1852
1879
"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"
1854
1882
}
1855
1883
]
1856
1884
----
@@ -2596,12 +2624,13 @@ AS Milliseconds;
2596
2624
====
2597
2625
2598
2626
[#fn-date-str-to-utc]
2599
-
== STR_TO_UTC(date1)
2627
+
== STR_TO_UTC(date1 [, [input-fmt,] fmt])
2600
2628
2601
2629
=== Description
2602
2630
2603
2631
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.
2605
2634
2606
2635
=== Arguments
2607
2636
@@ -2611,6 +2640,20 @@ This is the date to convert to UTC.
2611
2640
+
2612
2641
If this argument is not a valid date format, then `null` is returned.
2613
2642
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
+
2614
2657
=== Return Value
2615
2658
2616
2659
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.
2621
2664
[source,sqlpp]
2622
2665
----
2623
2666
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;
2625
2669
----
2626
2670
2627
2671
.Results
@@ -2630,19 +2674,21 @@ STR_TO_UTC('1111-11-11') as short_date;
2630
2674
[
2631
2675
{
2632
2676
"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"
2634
2679
}
2635
2680
]
2636
2681
----
2637
2682
====
2638
2683
2639
2684
[#fn-date-str-to-tz]
2640
-
== STR_TO_TZ(date1, tz)
2685
+
== STR_TO_TZ(date1, tz [, [input-fmt,] fmt])
2641
2686
2642
2687
=== Description
2643
2688
2644
2689
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.
2646
2692
2647
2693
=== Arguments
2648
2694
@@ -2657,28 +2703,48 @@ A string, or any valid xref:n1ql-language-reference/index.adoc[expression] which
2657
2703
+
2658
2704
If this argument is not a valid timezone, then `null` is returned.
2659
2705
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
+
2660
2720
=== Return Value
2661
2721
2662
2722
A single date string representing the date string converted to the specified timezone.
2663
2723
2724
+
[[ex-str-to-tz]]
2664
2725
=== Examples
2665
2726
2666
2727
====
2667
2728
[source,sqlpp]
2668
2729
----
2669
2730
SELECT STR_TO_TZ('1111-11-11T00:00:00+08:00', 'America/New_York') as est,
2670
2731
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,
0 commit comments