3
The time is appearing for the user.
My question: it is possible to hide the time and show only the date?
How are you showing:
Model code:
View code:
3
The time is appearing for the user.
My question: it is possible to hide the time and show only the date?
How are you showing:
Model code:
View code:
6
Instead of using the method .ToString("dd/MM/yyyy")
use the .ToShortDateString()
, because it will do the conversion to string disregarding the time, but the coolest is that it will follow the rules defined in CultureInfo
of your application. That is, if you are in Portuguese (en-BR) 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 pick up the value through the Value
.
if(item.DateInicial.HasValue){ item.DateInicial.Value.ToShortDateString(); }
There are many other methods in the class DateTime
.
Perfect.. It worked.
1
Try using String Format, example .ToString("dd/MM/yyyy")
, in the case:
@Html.ActionLink(item.DataInicial.Value.ToString("dd/MM/yyyy"), "Index", new { apuracaoSelecionada = item.ApuracaoIcmsID })
Opa, it worked, as the field is "Datetime?" I needed to put (item.DataFinal.Value.Tostring("dd/MM/yyyy") the "Value" tbm, thank you.
True! I’d forgotten the Nullable
, corrected in the example.
1
As you are manually displaying the date by doing Tostring(), you just specify a formatter:
item.DataInicial.ToString("dd/MM/yyyy")
Opa, it worked, as the field is "Datetime?" I needed to put (item.DataFinal.Value.Tostring("dd/MM/yyyy") the "Value" tbm, thank you.
0
Replace the variable DateTime
by a variable Date
Browser other questions tagged c# asp.net-mvc .net asp.net-mvc-5
You are not signed in. Login or sign up in order to post.
If possible place the source code instead of an image of it.
– rray