skip to Main Content

Would anyone have any advice on how to hardcode a specific date into my SELECT clause?

I’m trying to force a date into my query so I can reference it later, but unsure how to go about this.

Thanks in advance!
Sam

TL;DR Having issues writing a specific date into the SELECT in Athena/SQL

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for your help all - I've managed to do what I needed to do by using this:

    (CAST("date_trunc"('month', "date_add"('month', -1, current_date)) AS date)

    This has locked the date I need to use until the next month rolls around and it'll then update accordingly.

    Thanks for all your help!


  2. Here are a few ways to hardcode a timestamp to a column:

    select 
         timestamp '2023-07-07 12:34:56' as ts,
         date '2023-07-07' as dt,
         from_unixtime(1688733296) as unix_time
    

    If you’re using Athena engine v3.0 (Trino), you can use this reference:
    https://trino.io/docs/current/functions/datetime.html

    Otherwise, you’ll want the Presto documentation:
    https://prestodb.io/docs/current/functions/datetime.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search