Copied to clipboard

Flag this post as spam?

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


  • mikkel 143 posts 365 karma points
    Mar 04, 2019 @ 07:43
    mikkel
    0

    i need help with my datetime

    Hi every one.

    I want to show the date where my evenst are created but it shows 01 januar to everything events, why is that. I am using globalization da-dk here is the code i use for my datetime

    @(Model.Content.GetPropertyValue<DateTime>("createDate").ToString("dd. MMMM", new CultureInfo("da-dk"))) 
    

    enter image description here

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 04, 2019 @ 08:42
    Søren Gregersen
    0

    that indicates that the value is not ready - of you to a .ToString() (without format) you will see the value is most likely 1900-01-01 00:00:00

    Do you have a typo in you property alias?

  • mikkel 143 posts 365 karma points
    Mar 04, 2019 @ 14:30
    mikkel
    0

    how can i fix it :D

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Mar 04, 2019 @ 14:13
    Steve Morgan
    0

    You're using Model.Content but you seem to be looping through content.. are you sure you should not have something like

    currentEventItem.GetPropertyValue

    • I think you're getting the createDate of the event listing page each time rather than the one for each event.
  • mikkel 143 posts 365 karma points
    Mar 04, 2019 @ 14:26
    mikkel
    0

    Hi Steve i dont now how to use it. It seems to that no matter what i try then i get the date 01 januar or northing ? :D

    and if i use @Umbraco.Field("createDate", formatAsDate: true) i get what i want but in english and i want it to be danish :D

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Mar 04, 2019 @ 17:12
    Steve Morgan
    0

    Show us your code.. including the loop!

  • mikkel 143 posts 365 karma points
    Mar 04, 2019 @ 17:53
    mikkel
    0

    Here is my code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Begivenheder>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @using System.Globalization;
    @{
        Layout = "master.cshtml";
        var selection = Model.Content.Site().FirstChild("begivenheder").Children()
                            .Where(x => x.IsVisible())
                            .OrderBy("CreateDate desc");
    }
    <!-- Main Content -->
    @{
    
        int pageSize = 5; // How many items per page
        int page; // The page we are viewing
    
        /* Set up parameters */
    
        if (!int.TryParse(Request.QueryString["page"], out page))
        {
            page = 1;
        }
    
        /* This is your basic query to select the nodes you want */
    
        var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "nyBegivenhed").OrderBy("CreateDate desc");
        int totalNodes = nodes.Count();
        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
    
        /* Bounds checking */
    
        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
            page = 1;
        }
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-md-10 mx-auto">
                    <h1 class="main-page-heading">@Umbraco.Field("navnNyBegivenhed")</h1>
                    @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
                    {
                        <div class="post-preview">
    
                            <h2 class="post-title">@item.GetPropertyValue("navnNyBegivenhed")</h2>
    
                           <!--  here is my datetime code -->
                            <p class="post-meta">Skrevet af:&nbsp;@Umbraco.Field("creatorName")&nbsp;Den.&nbsp;@(Model.Content.GetPropertyValue<DateTime>("createDate").ToString("dd. MMMM", new CultureInfo("da-dk"))) </p>
                            <p>@Umbraco.TruncateByWords(item.GetPropertyValue("beskrivelseBegivenhed").ToString(), 20)</p>
                            <a href="@item.Url" class="btn btn-danger btn-pagination">Se begivenhed</a>
                        </div>
                        <hr />
                    }
                    @{
                        if (totalPages > 1)
                        {
                            <div class="pagination-class">
                                <ul class="pagination">
                                    @if (page > 1)
                                    {
                                        <li><a style="margin-right: 10px;" class="btn btn-danger btn-pagination" href="?page=@(page-1)">Tilbage</a></li>
                                    }
                                    @*@for (int p = 1; p < totalPages + 1; p++)
                                        {
                                            <li style="margin-right: 10px;" class="@(p == page ? "active" : string.Empty) btn btn-danger btn-pagination">
                                                <a href="?page=@p">@p</a>
                                            </li>
                                        }*@
                                    @if (page < totalPages)
                                    {
                                        <li><a style="margin-right: 10px;" class="btn btn-danger btn-pagination" href="?page=@(page+1)">Næste</a></li>
                                    }
                                </ul>
                            </div>
                        }
                    }
                </div>
            </div>
        </div>
    }
    
            }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 04, 2019 @ 18:11
    Søren Gregersen
    0

    Did you try @item.GetPropertyValue<DateTime>("createDate").ToString("dd. MMMM", new CultureInfo("da-dk")))

  • mikkel 143 posts 365 karma points
    Mar 04, 2019 @ 18:20
    mikkel
    0

    Yes and it is the same result🙂

  • mikkel 143 posts 365 karma points
    Mar 05, 2019 @ 08:36
    mikkel
    0

    It is stil the same. I dont get it whats wrong with the code :) you can see the date 01 Januar on every events

    enter image description here

    And here is my code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Begivenheder>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @using System.Globalization;
    @{
        Layout = "master.cshtml";
        var selection = Model.Content.Site().FirstChild("begivenheder").Children()
                            .Where(x => x.IsVisible())
                            .OrderBy("CreateDate desc");
    }
    <!-- Main Content -->
    @{
    
        int pageSize = 5; // How many items per page
        int page; // The page we are viewing
    
        /* Set up parameters */
    
        if (!int.TryParse(Request.QueryString["page"], out page))
        {
            page = 1;
        }
    
        /* This is your basic query to select the nodes you want */
    
        var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "nyBegivenhed").OrderBy("CreateDate desc");
        int totalNodes = nodes.Count();
        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
    
        /* Bounds checking */
    
        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
            page = 1;
        }
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-md-10 mx-auto">
                    <h1 class="main-page-heading">@Umbraco.Field("navnNyBegivenhed")</h1>
                    @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
                    {
                        <div class="post-preview">
    
                            <h2 class="post-title">@item.GetPropertyValue("navnNyBegivenhed")</h2>
    
    
                            <p class="post-meta">Skrevet af:&nbsp;@Umbraco.Field("creatorName")&nbsp;Den.&nbsp;@(item.GetPropertyValue<DateTime>("createDate").ToString("dd. MMMM", new CultureInfo("da-dk"))) </p>
                            <p>@Umbraco.TruncateByWords(item.GetPropertyValue("beskrivelseBegivenhed").ToString(), 20)</p>
                            <a href="@item.Url" class="btn btn-danger btn-pagination">Se begivenhed</a>
                        </div>
                        <hr />
                    }
                    @{
                        if (totalPages > 1)
                        {
                            <div class="pagination-class">
                                <ul class="pagination">
                                    @if (page > 1)
                                    {
                                        <li><a style="margin-right: 10px;" class="btn btn-danger btn-pagination" href="?page=@(page-1)">Tilbage</a></li>
                                    }
                                    @*@for (int p = 1; p < totalPages + 1; p++)
                                        {
                                            <li style="margin-right: 10px;" class="@(p == page ? "active" : string.Empty) btn btn-danger btn-pagination">
                                                <a href="?page=@p">@p</a>
                                            </li>
                                        }*@
                                    @if (page < totalPages)
                                    {
                                        <li><a style="margin-right: 10px;" class="btn btn-danger btn-pagination" href="?page=@(page+1)">Næste</a></li>
                                    }
                                </ul>
                            </div>
                        }
                    }
                </div>
            </div>
        </div>
    }
    
            }
    
  • Ole Martin Bakke 112 posts 624 karma points
    Mar 05, 2019 @ 08:58
    Ole Martin Bakke
    100

    I think CreateDate is a Umbraco-property, so you can do:

    @item.CreateDate.ToString("dd. MM")
    

    If you've got a single language site, you can also set the default language to danish. In the "Settings"-section under Language you probably got English. Click on it at select danish from the dropdown. You could also add Danish as a language in the same place and on your root-node in "Content" right-click and selevt "Set domain". Here you also can select one of the installed languages.

  • mikkel 143 posts 365 karma points
    Mar 05, 2019 @ 09:04
    mikkel
    0

    that is also what i got to :D her is what i didt thanks for the help eveyone :D

     @item.CreateDate.ToString("dd. MMMM yyyy", new CultureInfo("da-dk"))
    
Please Sign in or register to post replies

Write your reply to:

Draft