How do I convert SQL's convert(varchar,datefie

2019-06-13 19:01发布

问题:

How do I convert SQL's convert(varchar,datefield,106) to LINQ?

回答1:

You can get a string representation of a date by using ToString()

myDate.ToString()

and a date representation of a string by parsing it.

DateTime.Parse(myDateString)

You just need to include your conversion in your select clause.

from myRecord in myDataContext.MyTable
     select new {myStringDate = myRecord.myDate.ToString()};


标签: linq-to-sql