Skip to main content

Umbraco 8 - Calculate number of days past / between two dates

 

DateTime parsedDate = DateTime.Parse(item.Value<DateTime>("testimonailDate").ToString("dd MMMM yyyy"));

var daysPast = (DateTime.Today - parsedDate).TotalDays;

 @if(daysPast == 1)

                                                {

                                                    <span class="days-ago">@daysPast  day ago</span>

                                                }

                                                else

                                                {

                                                     <span class="days-ago">@daysPast  days ago</span>

                                                }

Comments

Popular posts from this blog

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

This is a Simple Contact From done in C# .Net and also can be used in Umbraco.  Paste the code in to Visual Web Developer for a better view. The important bits are coment in the second file.  One of the Commented out lines highlights how to get the mailto address from an Umbraco field. The code Below includes the myContactForm.ascx.cs codebehind file and the myContactForm.ascx file. 1) The myContactForm.ascx file:  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactFormforPublications.ascx.cs" Inherits="usercontrols_ContactFormPublications" %> <div class="contact-form" id="contactForm" runat="server">     <h3>Request a Publication</h3>     <div class='int'>         <form runat="server">         <asp:Panel DefaultButton="contactFormSubmit" runat="server">         <fieldset>             <div class='

Umbraco 8 Pagination

Umbraco 8 Pagination / Paging: @inherits Umbraco.Web.Mvc.UmbracoViewPage @{     Layout = "master.cshtml";         var pageSize = 8;     if(Model.HasValue("numberOfItemsPerPage")){     pageSize = Model.Value<int>("numberOfItemsPerPage");}         var page = 1; int.TryParse(Request.QueryString["page"], out page);     @* This line assumes you have a property called lastUpdated*@     var items = Model.Children().OrderByDescending(x => x.Value("lastUpdated"));     @* Remove the line above and use this line to keep it simple *@     @* var items = Model.Children()); *@             var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);     if (page > totalPages)     {         page = totalPages;     }     else if (page < 1)     {         page = 1;     } } @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize))             {            <a href="@item.