The time is showing up for the user.
My question: is it possible to hide the time and show only the date?
How are you looking:
Modelcode:
View code:
The time is showing up for the user.
My question: is it possible to hide the time and show only the date?
How are you looking:
Modelcode:
View code:
Instead of using the .ToString("dd/MM/yyyy")
method, use .ToShortDateString()
because it will convert to string regardless of the time, but the cool thing is that it will follow the rules set in the CultureInfo
of your application. That is, if it is in Portuguese (pt-BR) it will be dd/MM/yyyy
, but if it is in English (en-US) it will be mm/dd/yyyy
.
item.DataInicial.ToShortDateString() // somente a data (como solicitou)
item.DataInicial.ToShortTimeString() // somente a hora
If your field is DateTime
? (nullable), you will need to get the value through Value
.
if(item.DateInicial.HasValue){ item.DateInicial.Value.ToShortDateString(); }
There are many other methods in the DateTime
class.
As you are manually displaying the date by making ToString (), you simply specify a formatter:
item.DataInicial.ToString("dd/MM/yyyy")
Try to use String Format, example .ToString("dd/MM/yyyy")
, in case:
@Html.ActionLink(item.DataInicial.Value.ToString("dd/MM/yyyy"), "Index", new { apuracaoSelecionada = item.ApuracaoIcmsID })
Replace DateTime
with a variable Date