The sample he posted wasn't sending dates to DateDiff() - it actually works fine with those properties (from XSLT, that is - but I can't see why it shouldn't work in Razor too).
Hi, Keith, Both CreateDate and UpdateDate are regular non-dynamic properties of DynamicNode. Since that they are typed as DateTime and you cannot pass them to the DateDiff method because it expects strings. If you much want to use the very DateDiff you can do it getting {Create/Update}Date-s converted to strings:
var diff = umbraco.library.DateDiff(Model.CreateDate.ToString("s"), Model.UpdateDate.ToString("s"), "m");
However you absolutely don't need it - since these props are DateTime-typed and you can write simply:
Get difference between CreateDate and UpdateDate in Razor
What's the best way to do this? Using umbraco.library.DateDiff doesn't seem to work. I'm not sure DateDiff works at all with CreateDate and UpdateDate, since it seems to expect a different format. http://our.umbraco.org/forum/developers/xslt/15697-Hide-nodes-which-haven%27t-been-updated
Hi Keith,
The sample he posted wasn't sending dates to DateDiff() - it actually works fine with those properties (from XSLT, that is - but I can't see why it shouldn't work in Razor too).
/Chriztian
Hi, Keith, Both CreateDate and UpdateDate are regular non-dynamic properties of DynamicNode. Since that they are typed as DateTime and you cannot pass them to the DateDiff method because it expects strings. If you much want to use the very DateDiff you can do it getting {Create/Update}Date-s converted to strings:
However you absolutely don't need it - since these props are DateTime-typed and you can write simply:
Thanks, this works. I'd assumed they were strings, but I guess I should've tried subtracting them as dates first. This leads me to a more fundamental question: http://our.umbraco.org/forum/developers/razor/28172-Best-way-to-check-type-of-properties-on-Razor-Model-object
is working on a reply...