Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

SQL Query Translation - DateTrunc

Hello,   Can someone please help me get this query adjusted for SQL statement? It works in a web-based report in Solar Winds but not in SQL.   DateTime BETWEEN AddMonth(-1,DateTrunc('month', GETU...
  • v-juanli-msft's avatar
    7 years ago

    Hi Anonymous 

    If you want to convert the following code to SQL code,

    DateTime BETWEEN AddMonth(-1,DateTrunc('month', GETUTCDATE())) AND DateTrunc('month', GETUTCDATE())

     

    You could try the following SQL in SQL Server

    BETWEEN 
    DATEADD(MONTH,DATEDIFF(month, 0,GETUTCDATE() )-1,0) 
    AND 
    DATEADD(month, DATEDIFF(month, 0,GETUTCDATE() ), 0)
    

     

    Best Regards
    Maggie

     

    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.