1

I'm trying to populate a gridview with, among other things, a date field using a LINQ query that pulls data from an Oracle database. My problem is the date format that winds up displaying in the gridview is: MM/DD/YYYY HH:MM:SS. I only want to show MM/DD/YYYY. What change do I need to make to my query to achieve this?

 Dim InfoDetails = 
    From Lines In dtMain _
    Where Lines.Field(Of String)("ULTIMATE_PARENT_NAME") = lstUPs.SelectedItem.ToString _
        And Lines.Field(Of String)("CHANGE_TYPE") = Chng_Type.ToString _     
        And Not Lines.Field(Of String)("WARNING_TYPE").StartsWith("WARNING: DATA L") _
    Group By Change_Title = Lines.Field(Of String)("TITLE"), _
             Change_Details = Lines.Field(Of String)("DESCRIPTION"), _
             Effective_Date = Lines.Field(Of Date)("EFFECTIVE_DATE"), _
             Change_Type = Lines.Field(Of String)("CHANGE_TYPE") _
    Into Fieldname = Group, Count()
4

1 回答 1

3

You can either specify the format in the grid (recommended) or change the output type to a string:

Effective_Date = Lines.Field(Of Date)("EFFECTIVE_DATE").ToString("MM/dd/yyyy"), _

I would strongly recommend setting the format in the grid, but since you didn't specify anything about the UI I can't give any specific advice.

Some drawbacks of converting to string are:

  1. Sorting would be inaccurate with the format you've chosen
  2. You can't re-use this for other UIs that would want a different format.
于 2013-04-30T19:46:41.767 回答