Fetching Current Date in Hive

In this article, we will see how to fetch current date or current date-time in lower and higher versions of Apache Hive.

SELECT UNIX_TIMESTAMP():
SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP);
The instructions above yield the current “date and time” in seconds. This implies that the result will be a big integer value representing the number of seconds between the Unix epoch and the current date and time (this means as of now).

SELECT UNIX_TIMESTAMP(CURRENT_DATE);
The above command returns the total number of seconds between Unix epoch to current “date”.

SELECT TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP()));
The above command will help in fetching the current date (excluding the time stamp).

The above commands are helpful if you are using Hive older versions, however if you are using Hive 2.0 or later versions, you can simply use the below to fetch just date or date with timestamp:

SELECT CURRENT_DATE;

SELECT CURRENT_TIMESTAMP;

Hope you find this article helpful.

Please subscribe for more interesting updates.

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s