Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select current date in Hive SQL

Tags:

hive

hiveql

How do we get the current system date in Hive? In MySQL we have select now(), can any one please help me to get the query results. I am very new to Hive, is there a proper documentation for Hive that gives the details information about the pseudo columns, and built-in functions.

like image 896
Elingela Avatar asked Jul 28 '13 07:07

Elingela


People also ask

How do I get the current timestamp in Hive?

Hive provides few date functions to get the current timestamp values. The functions are current_timestamp() and unix_timestamp(). The format of the timestamp value is 'YYYY-MM-DD HH:MM:SS. sss'.

How does Hive define date?

DATE values are represented in the form YYYY-MM-DD. Example: DATE '2014-12-07'. Date ranges allowed are 0000-01-01 to 9999-12-31. TIMESTAMP use the format yyyy-mm-dd hh:mm:ss[.

How do I compare dates in Hive?

from_unixtime(,'yyyy-MM-dd') converts to a string of the given format, e.g. '2012-12-28' date_sub(,180) subtracts 180 days from that string, and returns a new string in the same format. unix_timestamp(,'yyyy-MM-dd') converts that string back to an int.


1 Answers

According to the LanguageManual, you can use unix_timestamp() to get the "current time stamp using the default time zone." If you need to convert that to something more human-readable, you can use from_unixtime(unix_timestamp()).

Hope that helps.

like image 199
Lukas Vermeer Avatar answered Sep 23 '22 19:09

Lukas Vermeer