我有一个非常简单的linq statemnt从数据库中提取记录,我只是想知道如何从中删除时间部分?试过很多方法,包括.ToShortDateString,但它没有正确地从SQL数据库格式化,它只是添加了我能看到的数字。以下是我的Linq声明。
MSCDatabaseDataContext MSCDB = new MSCDatabaseDataContext();
var q = from row in MSCDB.Tbl_Campaigns
select new Campaign
{
CampaignID = row.CampaignId,
CampaignName = row.CampaignName,
Target = Convert.ToInt32(row.Target),
Discount = Convert.ToInt32(row.Discount),
CampaignStartDatesS = Convert.ToDateTime(row.StartDate) + " - " + Convert.ToDateTime(row.EndDate),
//CampaignSDate = Convert.ToDateTime(row.StartDate),
//CampaignEDate = Convert.ToDateTime(row.EndDate),
CurrentStatus = row.EndDate >= DateTime.Now && row.StartDate <= DateTime.Now ? "Active": row.StartDate >= DateTime.Now ? "Pending": row.CampaignStatus == 4 ? "Archived": "Closed",
Uptake = Convert.ToInt32(row.Uptake),
};
帮助将不胜感激。
答案 0 :(得分:2)
使用Date
属性。
var today == DateTime.Now.Date; // there is a DateTime.Today as well, which does the same
获取此实例的日期组件。
返回值
与此实例具有相同日期的新
DateTime
,时间值设置为午夜12:00:00(00:00:00)。