Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roger Withnell 128 posts 613 karma points
    Nov 13, 2015 @ 13:01
    Roger Withnell
    0

    Format date picker property

    I'm using MVC Razor.

    I have my date picker field with:

    @Model.Content.GetPropertyValue("date");

    How do I now format it? I want dd-MM-yyyy.

    I cant' make .ToString("dd-MM-yyyy") work.

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Per Olsson 47 posts 307 karma points
    Nov 13, 2015 @ 13:11
    Per Olsson
    101

    Use the Umbraco Helper.

    umbraco.library.FormatDateTime(Model.Content.GetPropertyValue("date").ToString(), "dd-MM-yyyy")
    

    https://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime/

  • M N 125 posts 212 karma points
    Oct 25, 2017 @ 16:13
    M N
    0

    Value Converter approach if you prefer to use built-in .net helpers.

    DateTime date = Model.Content.GetPropertyValue<DateTime>("date");
    

    and in your view

    <p>Date: @date.ToString("dd-MM-yyyy")</p>
    
Please Sign in or register to post replies

Write your reply to:

Draft