Select * from concat(YEAR(DATE_SUB(MAX(Column_name),60),MONTH(DATE_SUB(MAX(Column_name),60),-01)
The month()
yields only single digit for months until September i.e Jan returns 1
instead of 01
. Need help in handling this.
I am using this output to feed to another SELECT
query using TO_DATE
.
month()
function returns integer, that is why there is no leading zero. You can uselpad(month,2,0)
function to format month:Alternatively you can use
substr()
to extract year and month from the date:date_sub() function prior to Hive 2.1.0 (HIVE-13248) return type was a String because no Date type existed when the method was created. See here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF