sqltimestampgoogle-bigquerydayofweek

BigQuery Standart SQL: extract day-of-week name from timestamp


I'm Using BigQuery Standart SQL.

I need to convert a timestamp to Day-of-week name.

e.g. convert today's timestamp (2016-11-24 00:00:00) into a string: 'Thursday'

Thanks :)


Solution

  • Below is for BigQuery Standard SQL

    #standardSQL
    SELECT 
      CURRENT_DATE() AS day,
      FORMAT_DATE('%a', CURRENT_DATE()) AS weekday_name_abbreviated,
      FORMAT_DATE('%A', CURRENT_DATE()) AS weekday_name_full
    

    or

    #standardSQL
    SELECT 
      DATE('2016-11-24 00:00:00') AS day,
      FORMAT_DATE('%a', DATE('2016-11-24 00:00:00')) AS weekday_name_abbreviated,
      FORMAT_DATE('%A', DATE('2016-11-24 00:00:00')) AS weekday_name_full  
    

    result is

    day         weekday_name_abbreviated    weekday_name_full    
    2016-11-24  Thu                         Thursday