我有一個Linq
結果我只需要從DateTime
只選擇Date
。
我的查詢是這樣的:Linq - 從日期選擇日期時間
var UserTemplates = (from xx in VDC.SURVEY_TEMPLATE
where xx.USER_ID == userid && xx.IS_ACTIVE == 1
select new
{
xx.TEMPLATE_ID,
xx.TEMPLATE_NAME,
//CREATED_DATE = xx.CREATED_DATE.Value.Date
//CREATED_DATE = EntityFunctions.TruncateTime(xx.CREATED_DATE)
xx.CREATED_DATE
}).ToList();
這可能嗎? 任何幫助將不勝感激。
CREATED_DATE - `datetime` datatype
事實上,我將它綁定到一個控制爲DataSource
,並且控制同時顯示Date and Time
。但我只想date
顯示。
當我與CREATED_DATE = xx.CREATED_DATE.Value.Date
努力,這是給像一個錯誤:
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
什麼問題呢? – I4V
xx.CREATED_DATE.ToShortDateString()?什麼格式是CREATED_DATE? – andrewb