Hive Date Format Guide: YYYY-MM-DD Examples
In Hive, the date_format function can be used to format a date in a specific format. Here is an example of formatting a date using the date_format function.
Suppose there is a date column containing date data. To format the date as YYYY-MM-DD, you can use the following query:
SELECT date_format(date_column, 'yyyy-MM-dd') AS formatted_date
FROM table_name;
In the above query, ‘date_column’ is the name of the date column to be formatted, and ‘yyyy-MM-dd’ is the specified date format.
In addition to yyyy-MM-dd, there are other date format characters that can be used to format dates. Some common date format characters include:
- Year: A four-digit year
- MM: 2nd month
- dd: 2-digit date
- HH: The hours in the 24-hour clock.
- mm: minutes
- ss: seconds
You can select the date format that suits your needs.