How can I cast a string in the format 'dd-MM-yyyy' to a date type also in the format 'dd-MM-yyyy' in Hive?
Something along the lines of:
CAST('12-03-2010' as date 'dd-mm-yyyy')
How can I cast a string in the format 'dd-MM-yyyy' to a date type also in the format 'dd-MM-yyyy' in Hive?
Something along the lines of:
CAST('12-03-2010' as date 'dd-mm-yyyy')
try:
If I have understood it correctly, you are trying to convert a String representing a given date, to another type.
Note: (As @Samson Scharfrichter has mentioned)
There are a few ways to do it. And you are close to the solution. I would use the CAST (which converts to a DATE_TYPE):
or (depending on your pattern)
And if you decide to convert ISO8601 to a date type:
Hive has its own functions, I have written some examples for the sake of illustration of these date- and cast- functions:
Date and timestamp functions examples:
Convert String/Timestamp/Date to DATE
Convert String/Timestamp/Date to BIGINT_TYPE
Convert String/Timestamp/Date to STRING
Convert BIGINT unixtime to STRING
Convert String to BIGINT unixtime
Convert String to TIMESTAMP
Idempotent (String -> String)
Idempotent (Date -> Date)
Current date / timestamp
AFAIK you must reformat your String in ISO format to be able to cast it as a Date:
To display a Date as a String with specific format, then it's the other way around, unless you have Hive 1.2+ and can use
date_format()
=> did you check the documentation by the way?