C# 如何发送月份的日期范围

C# 如何发送月份的日期范围,c#,asp.net,C#,Asp.net,我必须将每月的第一天作为开始日期发送,将当天作为结束日期发送。我知道今天很热,但我不确定开始日期 endDate = DateTime.Today.ToShortDateString(); 但是如何设置开始日期的格式,使其返回当月的第一天 startdate = ?? 非常感谢您的帮助。startdate=endDate.AddDays(endDate.Day*-1+1) startdate=endDate.AddDays(endDate.Day*-1+1) 只需使用年和月的endDate值

我必须将每月的第一天作为开始日期发送,将当天作为结束日期发送。我知道今天很热,但我不确定开始日期

endDate = DateTime.Today.ToShortDateString();
但是如何设置开始日期的格式,使其返回当月的第一天

startdate = ??

非常感谢您的帮助。

startdate=endDate.AddDays(endDate.Day*-1+1)

startdate=endDate.AddDays(endDate.Day*-1+1)

只需使用年和月的
endDate
值,使用1作为日期,新建一个
DateTime
实例:

var startDate = new DateTime(endDate.Year, endDate.Month, 1);

只需使用年和月的
endDate
值,使用1作为日期,新建一个
DateTime
实例:

var startDate = new DateTime(endDate.Year, endDate.Month, 1);

从当前日期的年份和月份创建新的
DateTime
实例:

// Get currect date in a variable, to avoid repeated calls (as DateTime.Now changes)
DateTime today = DateTime.Today;

string startDate = new DateTime(today.Year, today.Month, 1).ToShortDateString();
string endDate = today.ToShortDateString();

从当前日期的年份和月份创建新的
DateTime
实例:

// Get currect date in a variable, to avoid repeated calls (as DateTime.Now changes)
DateTime today = DateTime.Today;

string startDate = new DateTime(today.Year, today.Month, 1).ToShortDateString();
string endDate = today.ToShortDateString();

不是日期名称,就像2012年1月5日12:00 AM不是日期名称,就像2012年1月5日12:00 AM