Linq 2 Sql DateTime format to string yyyy-MM-dd

Posted by Bogdan Maxim on Stack Overflow See other posts from Stack Overflow or by Bogdan Maxim
Published on 2010-03-11T19:46:09Z Indexed on 2010/03/11 19:49 UTC
Read the original article Hit count: 911

Filed under:
|
|
|

Basically, i need the equivalent of T-SQL CONVERT(NVARCHAR(10), datevalue, 126)

I've tried:

  1. from t in ctx.table select t.Date.ToString("yyyy-MM-dd") but it throws not supported exception
  2. 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.

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#