This is not working right here:
DateTime? _data = calDataExclusao.Date;
string nova_data = _data.ToString("dd/mm/yyyy");
The error is:
No overload for method 'ToString' takes 1 arguments
How do I remove the time part of a date?
This is not working right here:
DateTime? _data = calDataExclusao.Date;
string nova_data = _data.ToString("dd/mm/yyyy");
The error is:
No overload for method 'ToString' takes 1 arguments
How do I remove the time part of a date?
First of all, the date format is wrong. It should be dd/MM/yyyy
and not dd/mm/yyyy
, so you're picking up the minutes instead of the month.
Font : Custom Date and Time Format Strings
The problem is that you are using Nullable DateTime
and not DateTime
normal. You should do it this way
string nova_data = _data.Value.ToString("dd/MM/yyyy");
This is to convert DateTime
to string
, if you really want to remove the time part of a date you should do
DateTime novaData = _data.Value.Date;
This will cause the novaData
variable to be the same as the previous one, but with hours, minutes, and seconds reset.
Use:
_data.Value.ToShortDateString();