Copied to clipboard

Flag this post as spam?

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


  • Blake Watt (Clerke) 106 posts 351 karma points MVP 2x
    Sep 21, 2012 @ 16:00
    Blake Watt (Clerke)
    0

    Using DateTime with Umbraco

    My goal is to get the umbraco DatePicker w/Time (alias: "showDateAndStartTime") value from the document type "Time". I then need to compare to see if the dates are the same (I don't know how to do this) so that I can later list each time associated with the date in one section.

    The end functionality will allow the user to create multiple show times with Date/Times underneath one show name (usually max is 2). The calendar will show one date, the show name listed below, and then the various times that show happens on that date. I would like to do this for 4 dates (currently the code is setup to take 4 'time' document types which would need to change to take only 4 days - im not sure what exactly i would need to do for this either).

    Any help is greatly appreciated!

    ================================

    Content Tree Structure

    Performers (Id = 1057)
    -Performer Name (Document Type "Performer")
    --Show Name Example (Document Type "Show")
    --- ShowTime (Document Type "Time")

    ================================

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        var nextShows = Model.NodeById(1057).Descendants("Time").OrderBy("showDateAndStartTime").Take(4);

        if (Model.NodeTypeAlias == "Performer")
        {
            nextShows = Model.AncestorOrSelf(3).Descendants("Time").OrderBy("showDateAndStartTime").Take(4);
        }
       
        <div class="col">
            <header>
              <h3>Showroom Calendar</h3>
            </header>
            <div class="colCalendar">

                @foreach(var show in nextShows){
                    //if(){
                    <div class="divider">
                        <p>Date Listed Here</p>
                        <a href="@show.Parent.Url" class="peach">@show.Parent.Name</a>
                        <p>
                            <strong class="gray">
                            @*@foreach(){
                                Multiple Times Listed Here
                            }*@
                            </strong>
                        </p>
                    </div>
                    //}
                }
                <a href="/showroom-calendar.aspx" title="" class="button">See full calendar</a>
            </div>
        </div>
    }
  • TheSharpieOne 10 posts 84 karma points
    Sep 21, 2012 @ 18:50
    TheSharpieOne
    0

    You should compare the dateTime.Date (showDateAndStartTime.Date).  It will remove the times (hours, minutes, and seconds) and provide you with just the date (year, month, and day) the event occurs on.

    Since the events are coming is order, you can compare the current event in the loop to the previous event, if they are equal, both events occur on the same day and you should visually group them in your output, if they are different then don't group them.

  • Blake Watt (Clerke) 106 posts 351 karma points MVP 2x
    Sep 27, 2012 @ 21:38
    Blake Watt (Clerke)
    0

    Got it working!

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

     

    @{

        int counter = 1;

        var nextShows = Model.NodeById(1057).Descendants("Time").Where("showDateAndStartTime >= DateTime.Now");

     

        <div class="col">

            <header>

              <h3>Showroom Calendar</h3>

            </header>

          <div class="colCalendar">

            @if(nextShows.Count() > 0)

            {

              string prevDate = string.Format("{0:M}", DateTime.Now);

              foreach (var show in nextShows)

              {

                  

                string currDate = string.Format("{0:M}", show.showDateAndStartTime);

                if (currDate != prevDate && counter <=4)

                {

                  <div class="divider">

                    <p>@currDate</p>

                    <a href="@show.AncestorOrSelf(3).Url" class="peach">@show.AncestorOrSelf(3).Name</a>

                    <p>

                      <strong class="gray">

                         

                        @{

                            var currTime = string.Format("{0:t}", show.showDateAndStartTime);

                            string timeString = currTime;

                            int position = nextShows.IndexOf(show);

                            if(position < nextShows.Count()-1)

                            {

                                string nextDate = string.Format("{0:M}", nextShows[position + 1].showDateAndStartTime);

                                if(currDate == nextDate)

                                {

                                    var nextTime = string.Format("{0:t}", nextShows[position+1].showDateAndStartTime);

                                    timeString = string.Format("{0}, {1}", timeString, nextTime);

                                }

                            }

                        }

                          @timeString

                      </strong>

                    </p>

                  </div>

                  counter = counter + 1;

                }

                prevDate = currDate;

              }

            }else{

              <p>No Upcoming Shows</p>

            }

            <a href="/showroom-calendar.aspx" title="" class="button">See full calendar</a>

          </div>

        </div>

    }

Please Sign in or register to post replies

Write your reply to:

Draft