I am trying to store a date into hive variable but not able to use it later.
hive> select to_date(date_sub(last_day(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd')),1));
OK
2019-07-30
set my_date=select to_date(date_sub(last_day(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd')),1));
now I want to extract year and month out of my_date but it's not working.
hive> select date_format('${hiveconf:my_date}','yyyy-MM');
FAILED: ParseException line 1:85 missing ) at 'yyyy' near 'yyyy'
line 1:89 missing EOF at '-' near 'yyyy'
below statement is working:
hive> select date_format('2019-07-30','yyyy-MM');
OK
2019-07
Not sure what's happening. How can I refer to my_date variable and store year & month in another set of variable in hive.
set year_month_date = select date_format('${hiveconf:my_date}','yyyy-MM');