Section 9:99. Date Manipulation – Extracting information using Year,month,day, etc

1.year(date) – This function returns the year component of the given date.

Example: SELECT year(‘2022-03-05’); returns 2022

2.month(date) – This function returns the month component of the given date.

Example: SELECT month(‘2022-03-05’); returns 3

3.day(date) – This function returns the day of the month component of the given date.

Example: SELECT day(‘2022-03-05’); returns 5

4.hour(timestamp) – This function returns the hour component of the given timestamp.

Example: SELECT hour(‘2022-03-05 15:30:00’); returns 15

5.minute(timestamp) – This function returns the minute component of the given timestamp.

Example: SELECT minute(‘2022-03-05 15:30:00’); returns 30

6.second(timestamp) – This function returns the second component of the given timestamp.

Example: SELECT second(‘2022-03-05 15:30:00’); returns 0

These are just a few examples of date arithmetic functions in Hive. Hive provides many more built-in functions for handling date and time values.

Share this post