Hive date function to achieve day of week

前端 未结 6 887
無奈伤痛
無奈伤痛 2020-12-16 14:00

I\'m looking for a workaround or hive date functions that gives day of the week ,

Sunday - 1
Monday - 2
Tuesday - 3
Wednesday - 4
Thursday - 5
Friday - 6
Sat         


        
6条回答
  •  生来不讨喜
    2020-12-16 14:32

    As I said you need to write a UDF which will accept a string as parameter and return a string. Inside the UDF you need to do these steps:

    1.) Parse the input string using SimpleDateFormat(YYYYMMDD)

    2.) Use the Below code to get the day of week:

    Calendar c = Calendar.getInstance();
    c.setTime(yourDate);
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    

    3.) Use this dayOfWeek value in a case statement to get your weekday String and return that string.

    Hope this helps...!!!

提交回复
热议问题