I am wondering if I can get last month and current month in Redshift? I looked at functions at http://docs.aws.amazon.com/redshift/latest/dg/r_CURRENT_DATE_TIME_functions.html
For current month, I guess I can do the following:
LEFT(CURRENT_DATE, 7)
For previous month, I came up with the following:
LEFT(ADD_MONTHS(CURRENT_DATE, -1), 7)
But I am wondering if there is a simpler way of doing these?
LAST_DAY returns the date of the last day of the month that contains date. The return type is always DATE, regardless of the data type of the date argument.
CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD. CURRENT_DATE returns the start date for the current transaction, not for the start of the current statement.
GETDATE returns the current date and time in the current session time zone (UTC by default). It returns the start date or time of the current statement, even when it is within a transaction block.
Redshift offers a DATE_TRUNC('week', datestamp) function. Given any datestamp value, either a date or datetime, it gives back the date of the preceding Sunday.
SELECT EXTRACT(month FROM CURRENT_DATE);
SELECT EXTRACT(month FROM CURRENT_DATE - '1 month'::interval);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With