In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people have no idea about how to use the date function in Hive. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Date function UNIX timestamp to date function: from_unixtime syntax: from_unixtime (bigint unixtime [, string format])
Return value: string
Description: converts the UNIX timestamp (the number of seconds from 1970-01-01 00:00:00 UTC to the specified time) to the time format of the current time zone
For example:
Hive > select from_unixtime (1323308943 Magnesia MMdd') from dual
20111208
Get the current UNIX timestamp function: unix_timestamp syntax: unix_timestamp ()
Return value: bigint
Description: get the UNIX timestamp of the current time zone
For example:
Hive > select unix_timestamp () from dual
1323309615
Date to UNIX timestamp function: unix_timestamp syntax: unix_timestamp (string date)
Return value: bigint
Description: convert the date in the format "yyyy-MM-dd HH:mm:ss" to the UNIX timestamp. If the conversion fails, 0 is returned.
For example:
Hive > select unix_timestamp ('2011-12-07 13 purl 01purl 03') from dual
1323234063
Specified format date to UNIX timestamp function: unix_timestamp syntax: unix_timestamp (string date, string pattern)
Return value: bigint
Description: convert the date in pattern format to UNIX timestamp. If the conversion fails, 0 is returned.
For example:
Hive > select unix_timestamp ('20111207 13 HH:mm:ss' 01VR 03mm HH:mm:ss') from dual
1323234063
Date time to date function: to_date syntax: to_date (string timestamp)
Return value: string
Description: returns the date section in the date time field.
For example:
Hive > select to_date ('2011-12-08 10 from dual 03VR 01')
2011-12-08
Date transfer function: year syntax: year (string date)
Return value: int
Description: returns the year in the date.
For example:
Hive > select year ('2011-12-08 10 from dual 03VR 01')
2011
Hive > select year ('2012-12-08') from dual
2012
Date-to-month function: month syntax: month (string date)
Return value: int
Description: returns the month in the date.
For example:
Hive > select month ('2011-12-08 10 from dual 03VR 01')
twelve
Hive > select month ('2011-08-08') from dual
eight
Date transfer function: day syntax: day (string date)
Return value: int
Description: returns the day in the date.
For example:
Hive > select day ('2011-12-08 10 from dual 03VR 01')
eight
Hive > select day ('2011-12-24') from dual
twenty-four
Date to hour function: hour syntax: hour (string date)
Return value: int
Description: returns the hour in the date.
For example:
Hive > select hour ('2011-12-08 10 from dual 03VR 01')
ten
Date to minute function: minute syntax: minute (string date)
Return value: int
Description: returns the minutes in the date.
For example:
Hive > select minute ('2011-12-08 10 from dual 03VR 01')
three
Date-to-second function: second syntax: second (string date)
Return value: int
Description: returns the seconds in the date.
For example:
Hive > select second ('2011-12-08 10 from dual 03VR 01')
one
Date transfer function: weekofyear syntax: weekofyear (string date)
Return value: int
Description: the return date is the current number of weeks.
For example:
Hive > select weekofyear ('2011-12-08 10 from dual 03VR 01')
forty-nine
Date comparison function: datediff syntax: datediff (string enddate, string startdate)
Return value: int
Description: returns the number of days from the end date minus the start date.
For example:
Hive > select datediff ('2012-12-08) from dual
two hundred and thirteen
Date increment function: date_add syntax: date_add (string startdate, int days)
Return value: string
Description: returns the start date the date after startdate adds days days.
For example:
Hive > select date_add ('2012-12-08) from dual
2012-12-18
Date reduction function: date_sub syntax: date_sub (string startdate, int days)
Return value: string
Description: returns the date after the start date startdate minus days.
For example:
Hive > select date_sub ('2012-12-08) from dual
2012-11-28
After reading the above, have you mastered how to use the date function in Hive? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.