I have a table of data which I would like to order by the date. My date field is varchar on the database in the following format; dd/mm/yyyy
I am trying to return my data with the following code;
var q = from na in db.NewsArticles orderby (Convert.ToDateTime(na.articleCreated).ToString("yyyy-MM-dd")) descending select na;
return q;
However this throws the following error;
Method 'System.String ToString(System.String)' has no supported translation to SQL.
Could someone point me in the right direction please?
Skip the
.ToString("yyyy-MM-dd")EDIT
Since the DB collation does not seem to mach your date formatting, you can try this:
Where “en-GB” is the culture from which your formatting is used. (you might need to change that)