Date Formatting in HTML Template usign razor

Hi All,

I'm working on our HTML email ticket template.

I've made a copy of the Mobile Ticket template and have been able to make the changes that I need except for the date format.

The current format is YYYY-MM-DD which isn't the most user friendly, so I'm trying to change it to dd MMM yyyy  (e.g. 31 Dec 2020).

I've managed to convert the performanceDate var to a DateTime as follows:

DateTime date2 = ((DateTime)DateTime.ParseExact(performanceDate, "yyyy-MM-dd", null));
performanceDate = date2.ToShortDateString();

However, the only function available on the date2 is "ToShortDateString()".

My web research suggests there should be a ToString("dd MMM yyyy") that I can use, but this doesn't work and intelisense doesn't have ToString() for my date var.

Any ideas on how to format this date?

Many thanks,

Parents Reply
  • I **think** what might be happening here is that your var declaration (var myOrderId) is being assigned the integer type, and if you try to display an integer you must convert it to a string or you will get a type error.

    What if you used in your code block:

    string myOrderId =  Model.OrderProductView.Id.ToString();

    And then referenced it in your html code with:  @myOrderId 

    Does that make it work?

Children
No Data