Linq 2 Sql DateTime format to string yyyy-MM-dd
- by Bogdan Maxim
Basically, i need the equivalent of T-SQL CONVERT(NVARCHAR(10), datevalue, 126)
I've tried:
from t in ctx.table
select t.Date.ToString("yyyy-MM-dd")
but it throws not supported exception
from t in ctx.table
select "" + t.Date.Year + "-" + t.Date.Month + "-" + t.Date.Day
but i don't think it's an usable solution, because i might need to be able to change the format.
The only option I see is to use Convert.ToString(t.Date, FormatProvider), but i need a format provider, and I'm not sure it works either.