Hive date function to achieve day of week

前端 未结 6 895
無奈伤痛
無奈伤痛 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:31

    Expanding on iggy's answer, here is the query to get the days of the week. Adjust the query to set the first day of the week as necessary.

    SELECT current_date AS `Date`,
           CASE date_format(current_date,'u')
               WHEN 1 THEN 'Mon'
               WHEN 2 THEN 'Tues'
               WHEN 3 THEN 'Wed'
               WHEN 4 THEN 'Thu'
               WHEN 5 THEN 'Fri'
               WHEN 6 THEN 'Sat'
               WHEN 7 THEN 'Sun'
    END AS day_of_week
    

提交回复
热议问题