检查今天是否是第一个月

-4 ssms t-sql sql-server-2016

在我的搜索引擎上,我看到了多个结果来获得一个月的第一天,但​​我想做一些稍微不同的事情。在 SQL 2016 中,我想检查今天GetDate()是否是该月的第一天。

我该怎么做?

kev*_*hat 5

IF DAY(GetDate()) = 1
    print 'first of the month'
ELSE
    print 'not first of the month'
Run Code Online (Sandbox Code Playgroud)

或者

IF DATEPART(DAY, GETDATE()) = 1
    print 'first of the month'
ELSE
    print 'not first of the month'
Run Code Online (Sandbox Code Playgroud)