I have a date value in the format 04/05/2017 when adding this value to the MS SQL database (column format - date) is 04/05/2017 00:00:00. That is, the amount of time is automatically added, and it is always zeros. How can I get rid of the time display? Thank.

  • And what type of field, eh? I suppose DATETIME or another, having a component of time? so who is to blame ... change to DATE. Or are you convinced that it is DATE? check just in case ... And with problems DISPLAYING (not storing!) data, do not contact the server, but to the client who actually displays them. - Akina
  • @Akina, DATE field type. - Denis
  • Well, then you just need the correct formatting output, without a component of time. - Akina
  • Do not spawn topics. - Alexander Petrov
  • one
    How much can you repeat: format the date on the client ! Set the date column in which the date is displayed, the property DefaultCellStyle.Format = "yyyy.MM.dd" . Links to documentation: Format property, date / time formats. - Alexander Petrov

1 answer 1

Use the ToString() method; If the date and time are displayed somewhere as text, you can convert it like this (regardless of locale): date.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);

  • The date is displayed in the table. Where exactly should I add this code, do not tell? - Denis
  • Which table? Datagrid? Is it wpf? - klutch1991
  • yes DataGridView, this is a Windows Form. - Denis