Below table summarizes the different date functions supported in Hive.
Function |
Description |
Example |
Return current timestamp of the system. |
SELECT current_timestamp(); |
|
Extract day information from date. |
SELECT day('2021-02-05 05:37:23'); |
|
Extract day information from date. |
SELECT dayofmonth('2021-02-05 05:37:23'); |
|
Return difference between two dates |
SELECT datediff('2021-01-12', '2021-05-12'); |
|
Add number of days to given date |
SELECT date_add('2021-05-12', 5); |
|
Subtract number of days from given date. |
SELECT date_sub('2021-05-12', 5); |
|
Convert epoch seconds to the date in given format. |
SELECT from_unixtime(1649767043);
SELECT from_unixtime(1649767043, 'yyyy-MM-dd'); |
|
Return hour part of date. |
SELECT hour('2021-02-05 06:37:23'); |
|
Return minute part of date |
SELECT minute('2021-02-05 06:37:23'); |
|
Return month part of date |
SELECT month('2021-02-05 05:37:23'); |
|
Return second part of date |
SELECT second('2021-02-05 06:37:23'); |
|
Extract date. |
SELECT to_date('2021-02-05 05:37:23'); |
|
Return number of seconds from the Unix epoch (1970-01-01 00:00:00 UTC) |
SELECT unix_timestamp(); SELECT unix_timestamp('2022-01-01 00:00:00'); SELECT unix_timestamp('2022-01-01', 'yyyy-MM-dd'); |
|
Return week number of the date |
SELECT weekofyear('2021-01-12'); |
|
Extract year part of the date |
SELECT year('2021-02-05 05:37:23'); |
Previous Next Home
No comments:
Post a Comment