0

I created a DateTime Field in order to select the soccer match day and I used this field in order to create part of my slug string.

I have:

public class Match
{

    [Required, Display(Name = "Date du match")]
    [DataType(DataType.Date)]
    public DateTime? MatchDay { get; set; }

    [Required, Display(Name = "Mot-clé")]
    public string Slug
    {
        get { return "_" + MatchDay; }
    }
}

On my Index.cshtml page, my MatchDay field is well displayed for exemple with 25/07/2019, but my slug value displayed is not good because I get _25/07/2019 00:00:00. I would like to get _25/07/2019

Do you have any idea to do that ? I'm pretty new with C#/ASP.NET and I don't find anything about this issue.

Thank you

Essex
  • 6,042
  • 11
  • 67
  • 139
  • Didn't find .. I'm learning C#/ASP.NET since 1 week only, I'm from python environment ... I tried lot of things but without find the solution.. I tried to handle MatchDay field without to try handling Slug field – Essex Jul 25 '19 at 12:45
  • I don't have the choice, my job forces me to learn new environments .. But as I have some issues in my code and I don't know to solve each one, my searches are probably not optimal – Essex Jul 25 '19 at 12:49

2 Answers2

1

you can just print your date as you wish like this:

MatchDay.ToString("dd/MM/yyyy");

you can find more info here

Bruno Belmondo
  • 2,299
  • 8
  • 18
1

Using the current curture of the thread, the funcrion below with format and return only the date portion of the value.

MatchDay.ToShortDateString()
Ross Bush
  • 14,648
  • 2
  • 32
  • 55