当前位置 : 主页 > 编程语言 > c语言 >

SQL+C#实现获得当前月的第一天与最后一天

来源:互联网 收集:自由互联 发布时间:2021-06-04
话不多说,请看下面 //C# 代码int year = DateTime.Now.Year;int month = DateTime.Now.Month;DateTime firstDayOfThisMonth = new DateTime(year, month, 1);DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year
话不多说,请看下面
//C# 代码
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
DateTime lastDayOfThisMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));
//SQL代码
DECLARE @NOW DATETIME
DECLARE @FistDayOfThisMonth DATETIME 
DECLARE @LastDayOfThisMonth DATETIME
SET @NOW = GETDATE()
SET @FistDayOfThisMonth = @NOW - DAY(@NOW) + 1 
SET @LastDayOfThisMonth = DATEADD(MONTH, 1, @NOW - DAY(@NOW) + 1) - 1
SELECT @FistDayOfThisMonth
SELECT @LastDayOfThisMonth

以上就是本文的全部内容,希望对大家有所帮助,同时也希望多多支持易盾网络!

网友评论