我想不出一个简单的一个或两个内胆的第一天和最后一天将获得previous个月。
我的LINQ ifying的一项调查显示Web应用程序,他们挤在一个新的要求。
本次调查必须包括所有的服务请求为previous一个月。因此,如果在4月15日,我需要所有游行请求ID。
VAR RequestIds =(来自R在rdc.request
其中,r.dteCreated> = LastMonthsFirstDate和放大器;&安培;
r.dteCreated< = LastMonthsLastDate
选择r.intRequestId);
我只是想不出日期轻松无开关。除非我是盲人,可以俯瞰做它的内部方法。
解决方案 今天VAR = DateTime.Today;
VAR月=新的日期时间(today.Year,today.Month,1);
VAR第一= month.AddMonths(-1);
变种最后= month.AddDays(-1);
在网上他们,如果你真的需要一两行。
I can't think of an easy one or two liner that would get the previous months first day and last day.
I am LINQ-ifying a survey web app, and they squeezed a new requirement in.
The survey must include all of the service requests for the previous month. So if it is April 15th, I need all of Marches request ids.
var RequestIds = (from r in rdc.request
where r.dteCreated >= LastMonthsFirstDate &&
r.dteCreated <= LastMonthsLastDate
select r.intRequestId);
I just can't think of the dates easily without a switch. Unless I'm blind and overlooking an internal method of doing it.
解决方案var today = DateTime.Today;
var month = new DateTime(today.Year, today.Month, 1);
var first = month.AddMonths(-1);
var last = month.AddDays(-1);
In-line them if you really need one or two lines.