"An inch of time cannot be bought with an inch of gold."
- Chinese Proverb
You can use the current_date and current_timestamp functions to get the date and time. You must have a FROM clause. Above, we used the Order_Table with a LIMIT statement to retrieve today's date and timestamp.
You can use the to_date function to extract the day in yyyy-mm-dd format.
You can use the to_date function to extract the day in yyyy-mm-dd format.
The example above extracts the date from a time data type, adds days to a time and calculates a discount for an Order_Total.
The data type hive uses to store a date is String. You can use a substring functions to achieve the same, but the example above uses the regexp_extract function in hive.
The data type hive uses to store a date is String. Notice above that the date was a timestamp. We used a substring function to get just the date portion from the string.
The data type hive uses to store a date is String. You can use a concat function to get the date portion from the string.
The data type hive uses to store a date is String. You can use a concat function to get the date portion from the string.
The data type hive uses to store a date is String. You can use a concat function to get the date portion from the string.
This got a little tricky. By using the case statement, we were able to get the date perfectly formatted.
The example above calculates the number of orders per year per month for all orders in the year 1999.
The example above extracts the year, month and day from a time data type.
The example above extracts the hour, minute and seconds from a time data type. This example uses a literal date and time in order to better show technique.
This is the Add_Months Command. Using this command, you can add a month or many months to your date columns. Can you convert this to one year? There is no ADD_YEAR command!
Notice the clever techniques to add a year and seven years. Let the system do the tricky calculations.
Cast stands for Convert and Store. It temporarily changes a data type. Above, we changed the order_time to a date and the order_total to a decimal with a precision of 4.
You can calculate the number of months between two dates by using the MONTHS_BETWEEN command.
This example calculates the date of the following Monday from an Order_Date. The Monday date will be later than the Order_Date. We could also put in another day of the week.
This example calculates the date of the following Tuesday from an Order_Date. The Tuesday date will be later than the Order_Date. We could also put in another day of the week.
An interval is designed to add or subtract intervals. Above, we have added an interval of 1 day to our current_date.
An interval is designed to add or subtract intervals. Above, we have added an interval of 1 day to our current_date, which is the last day of the month. Some systems will error on an interval that merely adds a day when that day is an invalid date. Hadoop knows it is not leap year so the interval moves to March 1st.
Our example has added one day, three months and five years to our current_date. We also used the CAST command to take the time portion out of our one-day interval.