Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

LINQ convert to datetime in a query

$
0
0

I have the linq query below binding to a Gridview:

gvEvents.DataSource = dc.demand.Select(s => new
        {
            id = s.id,
            user = s.user.name,
            protocol = s.events.protocol,
            type_demand = s.type_demand,
            description = s.description,
            comment = s.comment,
            date_created = s.date_created
        })
        .ToList();
        gvEvents.DataBind();


I need to convert date_created field to a datatime string like "dd/MM/yyyy hh:mm" .
And I have to say that date_created is a nullable type in the db.

So I need to do something like: date_created = Convert.ToDateTime(s.date_created).ToString("dd/MM/yyyy hh:mm").

But as LINQ doesn't recognize Convert.DateTime and neither .ToString, i'm here to ask how can I do that.

Thanks in advance!


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>