Date extract functions
These functions return the corresponding year/month/day/hour/minute/second/millisecond/microsecond/nanosecond from a timestamp. The timestamp must be supplied as an argument to the function.
Syntax:
INTEGER year(<timestamp>)
INTEGER month(<timestamp>)
INTEGER day(<timestamp>)
INTEGER hour(<timestamp>)
INTEGER minute(<timestamp>)
INTEGER second(<timestamp>)
INTEGER millisecond(<timestamp>)
INTEGER microsecond(<timestamp>)
INTEGER nanosecond(<timestamp>)- timestamp: These functions expects a timestamp as the input argument.
- Return Value: INTEGER
Table 12-3 Timestamp date extract functions
Function Return Value yearReturns the year for the given timestamp. The returned value is in the range -6383 to 9999. monthReturns the month for the given timestamp, in the range 1 ~ 12. dayReturns the day of month for the timestamp, in the range 1 ~ 31. hourReturns the hour of day for the timestamp, in the range 0 ~ 23. minuteReturns the minute for the timestamp, in the range 0 ~ 59. secondReturns the second for the timestamp, in the range 0 ~ 59. millisecondReturns the fractional second in millisecond for the timestamp, in the range 0 ~ 999. microsecondReturns the fractional second in microsecond for the timestamp, in the range 0 ~ 999999. nanosecondReturns the fractional second in nanosecond for the timestamp, in the range 0 ~ 999999999.
Note:
If the argument is NULL or empty, the result is also NULL or empty.Example 12-28 Get consolidated travel details of the passengers from airline baggage tracking data
BaggageInfo table.SELECT DISTINCT
$s.fullName,
$s.bagInfo[].flightLegs[].flightNo AS flightnumbers,
$s.bagInfo[].flightLegs[].fltRouteSrc AS From,
concat ($t1,":", $t2,":", $t3) AS Traveldate
FROM baggageinfo $s, $s.bagInfo[].flightLegs[].flightDate AS $bagInfo,
day(CAST($bagInfo AS Timestamp(0))) $t1,
month(CAST($bagInfo AS Timestamp(0))) $t2,
year(CAST($bagInfo AS Timestamp(0))) $t3Explanation:
You can use the time functions to retrieve the travel date, month, and year. The concat function is used to concatenate the retrieved travel records to display them in the desired format on the application. You first use CAST expression to convert the flightDates to a TIMESTAMP and then fetch the date, month, and year details from the timestamp.
{"fullName":"Adam Phillips","flightnumbers":["BM604","BM667"],"From":["MIA","LAX"],"Traveldate":"1:2:2019"}
{"fullName":"Adelaide Willard","flightnumbers":["BM79","BM907"],"From":["GRU","ORD"],"Traveldate":"15:2:2019"}The query returns the flight details which can serve as a quick look-up for the passengers.