ToShortDateString() Macro Method Formatting

Eric Rovtar asked on March 4, 2016 15:48

Hi!

I'm using the ToShortDateString() macro method on a DateTime value returned from the database. This returns the standard format of mm/dd/yyyy, which is appropriate for my culture.

Our style guide requires the format to be mm.dd.yyyy (so periods instead of slashes).

Is there a way to do this with the default ToShortDateString() or do I need to build a custom one?

Ultimately, we actually want to end up with mm.dd in this instance, but in some cases throughout the site we will want the year.

Thanks!

-Eric

Correct Answer

Anton Grekhovodov answered on March 4, 2016 17:27

Hi Eric,

In K# you can use this code: {% String.FormatString("{0:MM.dd.yyyy}", DateTime.Now) #%}

2 votesVote for this answer Unmark Correct answer

Recent Answers


Bryan Soltis answered on March 4, 2016 18:03

Or you could use <%# FormatDateTime(DateTime.Now, "MM/dd/yyyy HH:mm") %>

Either should get what you need.

  • Bryan
0 votesVote for this answer Mark as a Correct answer

Eric Rovtar answered on March 4, 2016 18:08

Thanks, guys.

Anton, that's exactly what I was looking for.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.