Convert "date and time" to "date" in C#

Asked

Viewed 210 times

0

I need to convert "date and time" to "date" in C#, keeping the Datetime format (without converting to string).

In the code, I am converting an object to datetime, but I need to remove its time also to present in a DataGridTextColumn.

t.DataDeContrato = Convert.ToDateTime(row.ItemArray[6]);
  • Possible duplicate of Remove the time part of a date in c#

  • @Italorodrigo, apparently, did not read the question or the comments.

  • Relax, if I’m confused, the moderators will ignore my signage

  • Even though I didn’t read it right, he accepted the answer with the same solution as the question I cited as duplicate...

  • @Italorodrigo, Tobias Mesquita commented on the correct answer in the comments. Just read it... the problem was in XAML. Really, not read it right.

1 answer

1


the DateTime has a property called Date.

t.DataDeContrato = Convert.ToDateTime(row.ItemArray[6]).Date;
  • It didn’t work. Actually, I have to change the date on the component that displays the date...

  • <Datagridtextcolumn Binding="{Binding Path=Datadatatract}" Header="Contract Date" />

  • How do I format inside Datagridtextcolumn?

  • in this case your problem is another, not with C#, but with WPF. try the following: Binding="{Binding Path=DataDeContrato, StringFormat={}\{0:dd/MM/yyyy\}}"

  • Put the comment as the answer if it solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.