Morning, Title says it all. I cannot for the life of me figure out how to obtain the first weekday of the current month (or previous month etc.) in HQL.
So if today's date were to be evaluated, it should return 2/3/2020 as the date, since the 3rd was the first weekday of this month.
I've tried case statements to evaluate the first day of the month, and if it is a saturday, add 2 days, a sunday, add 1 but it is not working and I receive the following error: ERROR: Prepare error: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:452 extraneous input ',' expecting KW_THEN near ''line 1:626 extraneous input ',' expecting KW_THEN near ''
case when date_format(date_add(current_date, 1 - day(current_date)),'u')=6, then to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date)+2))
when date_format(date_add(current_date, 1 - day(current_date)),'u')=7, then to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date)+1))
else to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date))) end
Please help!
@Vamsi Prabhala
I tried this however I receive a result of 1. I need a date returned, specifically 2/3/2020 for this month.
case when date_format(date_add(current_date, 1 - day(current_date)),'u')> 5 then
to_date(mydate)= to_date(date_add(date_add(current_date, 1 - day(current_date)),8-cast(date_format(date_add(current_date, 1 - day(current_date)),'u') as int)%8))
else to_date(mydate) = date_add(current_date, 1 - day(current_date)) end