如何发送当月的日期范围
本文关键字:日期 范围 何发送 | 更新日期: 2023-09-27 18:34:38
>我必须将每月的第一天作为开始日期发送,并将结束日期作为当天发送。我知道很热,可以得到今天,但我不确定开始日期。
endDate = DateTime.Today.ToShortDateString();
但是如何格式化开始日期以使其返回该月的第一天?
startdate = ??
我真的很感激任何帮助。
从当前日期的年份和月份创建新的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();
只需使用年份和月份的endDate
值(使用 1 表示日期(更新一个 DateTime
实例:
var startDate = new DateTime(endDate.Year, endDate.Month, 1);
startdate = endDate.AddDays(endDate.Day * -1 + 1(;