0

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

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

2 Answers2

0

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

ChoNuff
  • 814
  • 6
  • 12
0

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!

XMehdi01
  • 5,538
  • 2
  • 10
  • 34