Jonny Wright Posted June 21, 2010 Share Posted June 21, 2010 In LINQ C# how can I display only the Date from a type DateTime? Link to comment https://www.neowin.net/forum/topic/912710-linq-c-show-only-date-from-datetime-type/ Share on other sites More sharing options...
0 mkrivacek Posted June 21, 2010 Share Posted June 21, 2010 On 21/06/2010 at 15:25, Jonny Wright said: In LINQ C# how can I display only the Date from a type DateTime? For example: namespace WindowsFormsApplication1 { using System; using System.Linq; using System.Windows.Forms; using System.Collections.Generic; public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class Customer { public Guid ID { get; set; } public string Name { get; set; } public DateTime Created { get; set; } public Customer() { } } private void button1_Click(object sender, EventArgs e) { List<Customer> customers = new List<Customer>(); customers.Add(new Customer() { ID = Guid.NewGuid(), Name = "AAA", Created = DateTime.Now }); customers.Add(new Customer() { ID = Guid.NewGuid(), Name = "BBB", Created = DateTime.Now }); customers.Add(new Customer() { ID = Guid.NewGuid(), Name = "CCC", Created = DateTime.Now }); var o = from customer in customers select new { ID = customer.ID, Name = customer.Name, CreatedFormatted = customer.Created.ToString("dd.MM.yyyy") // Add your date formatting here }; foreach (var customer in o) { Console.WriteLine(customer.ID + ", " + customer.Name + ", " + customer.CreatedFormatted); } } } } Link to comment https://www.neowin.net/forum/topic/912710-linq-c-show-only-date-from-datetime-type/#findComment-592792074 Share on other sites More sharing options...
Question
Jonny Wright
In LINQ C# how can I display only the Date from a type DateTime?
Link to comment
https://www.neowin.net/forum/topic/912710-linq-c-show-only-date-from-datetime-type/Share on other sites
1 answer to this question
Recommended Posts