Problem with substring from markup



I'm using a repeater and the following in markup:

<%# ((EPiServer.Core.PageData)Container.DataItem)["Date"]%>

I really would like to shorten the date with a substring method. I just don't get it to work... How can I do this?

Aug 02, 2013 12:42

What property type is your "Date"? If it is a DateTime, you cannot make a substring on it since substring is a method on a string.

To get a property value as a DateTime you need to cast it, for example: (DateTime)page["Date"]

See for some best practices about casting Properties and preparing for null values.

If you want to convert a DateTime to a string you need to perform a .toString() on it. Since there are ways to format a string on the DateTime.toString() method I think it would be better to use it instead of performing .toString().SubString();

See and for more information about DateTime string formats

Aug 02, 2013 14:29

I got it to work with the casting... Thanks!

Aug 07, 2013 10:01
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.