I have troubles formatting two datetime (actually, it’s just the time part) values in my LINQ query. The values for time I’m getting in my gridview (gvDaily) have the following format: “HH:mm:ss-HH:mm:ss”. What I’d like to have is to have “HH:mm-HH:mm” time format, but I’m not sure how to accomplish it. Needless to mention that it’s the Time part of the query that I have problems with.
var dailyList = (from d in db.Daily
select d).ToList();
gvDaily.DataSource = from d in dailyList
orderby d.Datum
select new { d.idDaily, d.Biljeske, d.Datum, d.EfektivnoSati, Tvrtka = d.Ticket.Firma.Naziv, DailyManager = d.Kontakt.Ime + " " + d.Kontakt.Prezime, Ticket = d.Ticket.Opis, Time= d.TimeFrom+ "-" + d.TimeTo, d.TimeFrom, d.TimeTo, d.Opis, d.Ticket.Zatvoren, d.Ticket.IzdanRacun, TicketNumber = d.Ticket.idTicket + "-" + d.Ticket.RedniBroj, d.Dolazak };
Thank you in advance!
P.S. Custom formatting doesn’t work so I’m trying to find some other ideas.
I don’t know whether LINQ to Entities supports custom formatting, but you could try
However, I’d personally keep the values as
DateTimevalues in the LINQ to Entities part, and only transform to text in the .NET code. In particular, different cultures have different preferred ways of representing times, so you should probably respect that. Separate “fetching the data” from “presenting the data”.