Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 11:04
    Kate
    0

    compare dates

    Hi

    I'm about to make a list of events.
    I want the date of the event compared to the current date. If the event date has passed today, it shall not appear.

    This is what I got so fare :-)

    @{ var today = DateTime.Now; }

    @for(var i =1; i < 5; i++)
    {
    var dateItem = @Model.GetPropertyValue("date" + i);
    <p>@today er i dag</p>
    if(dateItem < today){
    <p>Write something here if date haven't passed today</p>
    }

    }

    Hope you understand what I mean :-)



  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 03, 2013 @ 11:09
    Jeavon Leopold
    0

    Hi Kate,

    I'm pretty sure you are using a Mvc Partial View, but could you please confirm?

    Also just to check you have 5 properties in your document type with alias like "date1", "date2" etc...?

    Thanks,

    Jeavon

  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 11:37
    Kate
    0

    Sorry, I have no idea what Mvc Partial View means :-(

    The loop is working fine, so I dont think that is where the problem is. I think that it has something to do with the date format.

    I have tryed to make at total simple exampel:

    @{     var today = DateTime.Now;
    var dateItem = @Model.GetPropertyValue("date4");
    }
    @dateItem er den indtastet dato
    @today er i dag

    @if(@Model.date4 < @today){
    <p>I am smaller</p>
    }

    If I write

    @if(@Model.date4 < @today){
    <p>I am smaller</p>
    }

    it works fine

    but if i write

    @if(@dateItem < @today){
    <p>I am smaller</p>
    }

    it gives me an error: Error loading MacroEngine script (file: loop.cshtml)

     

  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 12:28
    Kate
    0

    I got the date right

    @for(var i =1; i < 5; i++)
    {
    if(Model.HasValue("item" + i)){

    var dateItem = @Model.GetPropertyValue("date" + i);
    var postDate = umbraco.library.FormatDateTime(dateItem.ToString(), "dd/MM/yyyy");
    var tester = umbraco.library.DateGreaterThanOrEqualToday(@dateItem);


    <p>I am @tester </p>
    <p>@Model.GetPropertyValue("item" + i) og @postDate</p>

    }

    }

    I have some other items that do not work, but I think it's best if I create a new question

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 03, 2013 @ 13:28
    Jeavon Leopold
    0

    Hi Kate,

    I would approach it like this:

    @for(var i =1; i < 5; i++)
    {       
      var dateItem = CurrentModel.GetPropertyValue("date" + i).AsDateTime();     
      <p>@today er i dag</p>
            if(dateItem < today){
              <p>Write something here if date haven't passed today</p>
          }
    }
    

    Jeavon

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies