Developer forum

Forum » CMS - Standard features » Razor - How do i Format date?

Razor - How do i Format date?

Hans Ravnsfjall
Reply

Hi

I have at an itemtype that uses a DateTime field, and I want to output the date in a certain format - ie. I want it to say 25. November, and not

For the time being, I am fetching the value like this to a variable

string dato = GetValue("Item.Date").ToString();

and output it as @dato

But whatever i have tried to format it, it won´t work.

 

As you migth notice, I am not an experienced razor C# specialist, so be gentle and thorough thank you :)

regards Hans


Replies

 
Thomas Schroll
Reply

Hi Hans

You can use format specifiers (https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx):

string dato = GetValue("Item.Date").ToString("d MMMM");

Also you can get a real date object from DW by using GetDate instead of GetValue.

Regards Thomas

 
Hans Ravnsfjall
Reply

Pefect thank you Thomas :)

GetValue would not work with formatting, but changed it to GetDate and the formatting works perfectly :)

Regards

Hans

 

You must be logged in to post in the forum