我找到了你能想到的每一种 DateTime 格式,除了我需要的一种:yyyymm。我该如何得到这个?
我正在使用以下代码:
List <string> routines = new List<string>();
routines.Add("1 - Routine");
routines.Add("6 - Planned Outage");
int year = 2011;
int quarter = 1;
DateTime timeframe = new DateTime(year, (quarter * 3), 01).AddMonths(1);
var results =
(from wo in WORKORDERs
join wot in WORKORDERTYPEs on wo.Wot_oi equals wot.Wotyoi
join pri in PRIORITies on wo.Prio_oi equals pri.Priooi
join s in SITEs on wo.BEparn_oi equals s.Siteoi
where wo.Audt_created_dttm.Value.Year >= year - 3 && wo.Audt_created_dttm.Value.Year >= 2006
&& wo.Audt_created_dttm < timeframe && (s.Id =="NM" || s.Id == "TH") &&
!wot.Id.Contains("stand") && !(wo.Ci_cnc_date != null && pri.Prioid != "1 - Routine" &&
pri.Prioid != "6 - Planned Outage") && (SqlMethods.Like(pri.Prioid, "1%") ||
SqlMethods.Like(pri.Prioid, "2%") || SqlMethods.Like(pri.Prioid, "3%"))
select new {PM = wo.Wosource, Site = s.Id, Priority = pri.Prioid, Worktype = wot.Id,
WoNumber = wo.Id, Description = wo.Aenm, CreateDate = wo.Audt_created_dttm,
CloseDate = wo.Clsdt_date,
MonthNum = String.Format("{0:yyyy mm}", wo.Clsdt_date),
Planning = routines.Contains(pri.Prioid) ? "Planned" : "Unplanned"});
我尝试使用:
MonthNum = String.Format("{0:yyyy mm}", wo.Clsdt_date)
这给了我正确的年份,但月份都是 00。我猜这是因为 wo.Clsdt_date 的格式与我的字符串格式不同(它是 mm/dd/yyyy)。
有任何想法吗?