Home > Net >  Snowflake getting yearmonth in numeric form SQL
Snowflake getting yearmonth in numeric form SQL

Time:12-30

I am writing a function to pull the dates in the past 12 months. I am thinking to use (Current_date - 1month) for endubg month and (current_date -13months) for the beginning month.

However, when I use Current_date function, it returns me to the value 2022-12-29. Ideally, I would want the value to be 202212 in numeric forms because of my database. Beginning month should be 202112 and the ending month should be 202211. Is there a way I could do this in SQL?

CodePudding user response:

We can use the TO_CHAR() function here:

SELECT TO_CHAR(CURRENT_DATE, 'YYYYMM');
  • Related