Skip to content
Advertisement

Date_Trunc not function working as expected

I am trying to use the Date_Trunc for MONTH function in a SQL statement but somehow it is not working for me. I am trying to pull entries which happen after April 1st, 2019. The raw date format from the Redshift database is this format which I am trying to group into month/year buckets: 2019-04-08T00:13:20.000Z

Input

Output

What am I doing wrong?

Advertisement

Answer

The DATE_TRUNC Function – Amazon Redshift takes timestamp as input and provides a timestamp as output:

For example:

Therefore, your line should read:

If you wish to have the output as a date, append ::date:

Also, note that the date converts into a timestamp as at midnight. This can cause a difference for some comparisons. For example:

will evaluate as True because it is comparing to midnight at the start of the day. This is different to comparing two dates (without timestamps).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement