数据库:MS Sql Server
日历:数据库设置的日历,通常为公历。
DECLARE
@YEAR_MONTH
varchar
(
6
)
SET
@YEAR_MONTH
=
'
200702
'
SELECT
DAY
(
DATEADD
(MM,
1
,
CONVERT
(
DATETIME
,
@YEAR_MONTH
+
'
01
'
,
112
))
-
DAY
(
CONVERT
(
DATETIME
,
@YEAR_MONTH
+
'
01
'
,
112
)))
Add at 2007年8月6日
DECLARE
@Year_Month
varchar
(
7
),
@FirstDayOfMonth
datetime
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
SET
@Year_Month
=
'
2007-02
'
SET
@FirstDayOfMonth
=
CONVERT
(
DATETIME
,
@Year_Month
+
'
-01
'
,
120
)
PRINT
@FirstDayOfMonth
SELECT
DAY
(
DATEADD
(MM,
1
,
@FirstDayOfMonth
)
-
DAY
(
@FirstDayOfMonth
))
转载于:https://www.cnblogs.com/Jinglecat/archive/2007/07/29/835786.html