Snowflake - Date casting/conversion/assignments

SQL Baby 161 Reputation points
2022-01-25T07:41:12.347+00:00

Hi,

I just started looking at Snowflake yesterday.
Am migrating some SQL server views for SSRS reports to snowflake...

In snowflake they have date time stamp columns with DataType TIMESTAMP_NTZ(9)

Am trying to create a view that returns rows where snowflake TIMESTAMP_NTZ(9) column = last day of the previous month for a monthly report.

eg:
"Snowflake timestamp column" = LAST_DAY(dateadd(month, -1, current_date() ) , 'month') -- last day of previous month

select last_day(dateadd(month, -1, current_date() ) , 'month') -- last day of previous month -- 2021-12-31

So I want "Snowflake timestamp column" = 2021-12-31
Obviously am doing something wrong because this assignment is not working?

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Joyzhao-MSFT 15,631 Reputation points
    2022-01-26T01:38:11.793+00:00

    Hi @SQL Baby ,
    Last Day of previous month:

    SELECT DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)  
    

    Best Regards,
    Joy


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Olaf Helper 47,436 Reputation points
    2022-01-26T12:14:20.413+00:00

    Snowflake SQL database is not a Microsoft product and so not supported on MS Q&A.

    Better post to a more related forum, e.g. at https://community.snowflake.com/s/

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.