Copied to clipboard

Flag this post as spam?

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


  • Stefan Joseph 19 posts 120 karma points
    Jul 24, 2018 @ 08:53
    Stefan Joseph
    0

    Unable to format Date Selector/Editor correctly

    In one of my Document Types, I have set up a Property named articleDate that is set to use a Date Selector/Editor. I've tried changing the format to DD-MM-YYYY and a number of other supported formats, but it always outputs like:

    7/19/2018 12:00:00am

    For reference, this is how I've rendered the property in the Template:

    <p>@Umbraco.Field("articleDate")</p>
    

    Am I missing something else that needs to be included?

    Thanks in advance!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 24, 2018 @ 09:13
    Jan Skovgaard
    101

    Hi Stefan

    Unfortunately setting the date format in the date datatype to a certain format for showing the dates in the backoffice does not mean it will be rendered in the same way when you render the output date. It only benefits the editors so they see the date in the correct format when editing the content.

    When you render the date you will need to ensure that the date is rendered in the same format. This can of course seem a bit silly but depending on the circumstances you might want to show one format for the editors but will need to format it in different ways depending on whether you're doing a multi-language site where the displaying of the date format might differ for instance.

    So as far as I know to achieve the rendering of the date that you want you will can do something like this:

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

    I hope this helps!

    /Jan

  • Stefan Joseph 19 posts 120 karma points
    Jul 25, 2018 @ 10:09
    Stefan Joseph
    0

    Thanks Jan, this worked perfectly!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 25, 2018 @ 08:22
    Jan Skovgaard
    0

    Hi Stefan

    Ok, if the HTML output you get is still showing the time then nothing makes sense to me anymore...since we specifically pass the formatting arguments...that's really odd... :-)

    Just to make sure that I'm not misunderstanding you - Could you please post a screendump of what things look like on your document type where you specify the date in Umbraco?

    And also a screendump of the frontend rendering of your website?

    Cheers, Jan

  • Stefan Joseph 19 posts 120 karma points
    Jul 25, 2018 @ 10:08
    Stefan Joseph
    0

    Jan, my apologies, this actually worked. Will mark your response as the correct solution.

    Thanks for your help!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 25, 2018 @ 10:48
    Jan Skovgaard
    0

    Hi Stefan

    Ahh, good to hear!

    Happy coding :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft