Copied to clipboard

Flag this post as spam?

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

  • Thomas 310 posts 597 karma points c-trib
    Sep 14, 2017 @ 13:00

    Date - time datatype output


    Is there a way to change the time format from:

    9/13/2017 2:30:00 PM


    9/13/2017 14:30 PM ??

  • Eric Frost 5 posts 88 karma points admin hq
    Sep 15, 2017 @ 07:59
    Eric Frost

    Hi Thomas,

    Maybe this might work for you:

    string formatted = dt_calc.ToString("HH:mm:ss");

    and if you using some custom data you should definitely look up Microsoft documentation on custom Datetime.

  • Lewis Smith 208 posts 617 karma points c-trib
    Sep 15, 2017 @ 08:34
    Lewis Smith

    Hi Thomas,

    You could do the following:

    When retrieving the date from your cms:

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

    (this may be some different syntax depending on the type of razor you are using) but you mainly need to render the item as a DateTime to be aloud to use the .ToString below.

    <p>@date.ToString("d MMM yy")</p>

    You can read up on date formatting here:

    If you show me some code samples you are working with I can try to resolve them for you.

    Thanks, Lewis

  • Thomas 310 posts 597 karma points c-trib
    Oct 05, 2017 @ 11:21


    ended up doing it like you showed!

    var date = Model.Content.GetPropertyValue<DateTime>("pageDate");
        if (date != DateTime.MinValue)
           <small>@date.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)</small>
  • Matthew Taylor 11 posts 85 karma points
    Jul 31, 2019 @ 13:54
    Matthew Taylor

    In Umbraco 8 you can get the formatting from

    Then use something like;

            @if (Model.HasValue("yourDateTimeProperty"))
                @(Model.Value<DateTime>("yourDateTimeProperty").ToString("dd MM yyyy"))
Please Sign in or register to post replies

Write your reply to: