Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show just the date and not date and time in a WPF datagrid?

I have a WPF datagrid with a binding to a class object that looks like the following:

<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate }" />

The property in the class is quite simple, as follows:

public DateTime OrderDate { get; set; }

When I'm populating this property I'm just sending DateTime.Date (date only, not time):

.Select(
    r =>
    new Customer
        {
            Persona = r.Persona,
            CustomerName = r.CustomerName,
            Email = r.Email,
            Organization = r.Organization,
            PhoneNumber = r.PhoneNumber,
            Street = r.Street,
            Suburb = r.Suburb,
            Postcode = r.Postcode,
            OrderDate = r.OrderDate.Date
        }))

Unfortunately this doesn't reflect in my WPF datagrid as that's showing the date, but then it's also showing the time (everywhere) as 12:00:00AM. How should I approach just having my WPF datagrid show the date only?

like image 760
Michael A Avatar asked Aug 21 '15 01:08

Michael A


1 Answers

Try this

<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate , StringFormat=d}" />

more info on string formattings here

like image 155
Juan M. Elosegui Avatar answered Sep 21 '22 16:09

Juan M. Elosegui