How do I get the number of days between two dates in AWS Athena

Looking around the web often gets me to non-Athena ways. So here we go. In AWS Athena you get the numbers of days between two dates like this:

SELECT date_diff('day', FROM_ISO8601_DATE('2024-06-13'), FROM_ISO8601_DATE('2024-05-13')) AS diff

The doc lies

As of today, the documentation lies, you cannot have ‘second’ as first parameter. If you need the seconds multiply the result by 24

something like

SELECT (date_diff('day', FROM_ISO8601_DATE('2024-06-13'), FROM_ISO8601_DATE('2024-05-13')))*24 AS diff_in_second
comments powered by Disqus