Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Dec 10, 2014 @ 08:24
    Daniel Larsen
    0

    How to compare dates? - u7

    Hi, I am trying to compare some dates. What I am trying to make, is a little macrescript that retrieves a date (DateHire) from the members and check if it is this employee anniversary, or if is going to happen within 14 days and if it happend maximum 14 days ago, but I cant get it to work!

    My code:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System.Linq
    @using umbraco.cms.businesslogic.member
    
    
        @{
        IEnumerable<umbraco.cms.businesslogic.member.Member > members = umbraco.cms.businesslogic.member.Member.GetAllAsList();
        {
            foreach (umbraco.cms.businesslogic.member.Member currentmembers in members) 
            {
                string d = umbraco.library.FormatDateTime(currentmembers.getProperty("DateHire").Value.ToString(), "d/M");
    
                var id = currentmembers.Id;
                var image = currentmembers.getProperty("Image").Value.ToString();
                var first = currentmembers.getProperty("NameFirst").Value.ToString();
                var middle = currentmembers.getProperty("NameMiddle").Value.ToString();
                var last = currentmembers.getProperty("NameLast").Value.ToString();
    
                @*Profile image*@
                if(String.IsNullOrEmpty(@image)) 
                {
                    image = "/css/img/avatar.png";
                }
                else {
                    @* Use the thumbnail *@
                    if (image.IndexOf(".") != -1)
                    {
                        var uploadNamePath = image.Split('.');
                        var thumbnailNamePath = uploadNamePath[0] + "_thumb" + "." + uploadNamePath[1];    
                        image = thumbnailNamePath;     
                    }
                }
    
                int now = int.Parse(DateTime.Today.ToString("yyyy")); @*Todays date*@
    
                var x = currentmembers.getProperty("DateHire").Value;   
                var y = string.Format("{0:yyyy}", @x); @*Date Of Hire *@
    
    
    
                if(y.IsInt()==true)
                {
                    var z = Convert.ToInt32(@y);
                    var years = now - z;
                    if (DateTime.Today.ToString("d/M") == d)
                    {
                    // Showing anniversary if it is today
                    }
    
                    else if (x < DateTime.Today.AddDays(14))
                    {
                    // Showing anniversary, if it going to happen within 14 days
                    }
    
                    else if (x > DateTime.Today.AddDays(14))
                    {
                    // Showing anniversary, if it has happend within 14 days
                    }
                }
    
            }
        }
    }
    

    I hope you can understand what I am trying to do, just ask if not.

    Thank you for your help!

    Daniel

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 10, 2014 @ 08:45
    Alex Skrypnyk
    3

    Hi Daniel,

    Did you try to use Convert.ToDateTime method?

    string date = "01/08/2008";
    DateTime dt = Convert.ToDateTime(date);  
    

    Thanks

  • Daniel Larsen 116 posts 381 karma points
    Dec 10, 2014 @ 09:47
    Daniel Larsen
    0

    Thank you!

    That sort of worked. Now I dont know how to make the if statement, to get the members from 14 days ago/after. I simply cannot figure out the logic

    I tried DateTime.Today < dt but todays date will never be smaller than date of hire, because it has happend and it will always be greater than it to then.

    Can you figure it out?

    Again thanks for you help. I am very greatfull :-)

    Daniel

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 10, 2014 @ 09:54
    Alex Skrypnyk
    1

    You are welcome Daniel,

    Try to use :

    DateTime.Today.AddDays(-14) < dt
    

    Thanks,

    Alexander

  • Daniel Larsen 116 posts 381 karma points
    Dec 10, 2014 @ 10:08
    Daniel Larsen
    0

    Thank you again.

    Trouble is, that it is also comparing with the year. So it wont work :-/

    Daniel

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 10, 2014 @ 11:06
    Alex Skrypnyk
    2

    Daniel, Maybe, this will help you ?

    DateTime.Today.DayOfYear < dt.DayOfYear
    
  • Charles Afford 1163 posts 1709 karma points
    Dec 10, 2014 @ 16:44
    Charles Afford
    0

    Hi Daniel, What version of Umbraco are you using?

    Charlie

  • Charles Afford 1163 posts 1709 karma points
    Dec 10, 2014 @ 17:36
    Charles Afford
    1

    Your code should be something like this :). I have done the dates down the bottom.

    You have to use a method called GetDays(). This gives you you a number of days between the two dates and you can use that as a comparison.

    Charlie :)

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService; IEnumerable

    foreach (IMember currentMember in members)
    {
        if(currentMember.HasProperty("DateHire"))
        {
            hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M");
        }
    
        memberId          = currentMember.Id;
    
        if(currentMember.HasProperty("DateHire"))
        { 
            imageId     = currentMember.GetValue("Image").ToString();
        }
    
        if(currentMember.HasProperty("DateHire"))
        {
            firstName   = currentMember.GetValue("NameFirst").ToString();
        }
    
        if(currentMember.HasProperty("DateHire"))
        {
           middleName  = currentMember.GetValue("NameMiddle").ToString(); 
        }
    
        if(currentMember.HasProperty("DateHire"))
        {
            lastName    = currentMember.GetValue("NameLast").ToString();
        }
    
    if(String.IsNullOrEmpty(imageId))
    {
        Int32.TryParse(imageId, out outImageId);
        if(outImageId > 0)
        {
            media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId);
            imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png";
        }
    }
    
    DateTime currentDateTime = DateTime.Now;
    DateTime outAnniversary = new DateTime();
    string anniversary;
    
    if(currentMember.HasProperty("DateHire"))
    {
        hireDate = currentMember.GetValue("DateHire").ToString();
    }
    if(currentMember.HasProperty("anniversary"))
    {
        anniversary = currentMember.GetValue("anniversary").ToString();
        DateTime.TryParse(anniversary, out outAnniversary);
    }    
    

    if (currentDateTime.Day == outAnniversary.Day) { // Showing anniversary if it is today }

    else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
    {
    // Showing anniversary, if it going to happen within 14 days
    }
    
     else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
    {
    // Showing anniversary, if it has happend within 14 days
    }
    }
    
  • Daniel Larsen 116 posts 381 karma points
    Jan 08, 2015 @ 10:10
    Daniel Larsen
    0

    Happy new year guys!

    First of all, sorry for the very late answer. I have not had a very nice christmas, because of a very bad breakup with my girlfriend. It really nocked me out.

    I hope you still want to help me. I really appreciate it!

    When I try using your code Charlie, it just outputs the raw code. I tried encapsulating it all with a @{}, but it did not work. Any advise?

    Thank you again.

    Daniel :-)

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    
        Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService; IEnumerable members = memberService.GetAllMembers(); string hireDate; int memberId; IMedia media; string imageId = String.Empty; int outImageId; string imageUrl; string firstName; string middleName; string lastName;
    
        foreach (IMember currentMember in members)
            {
                if(currentMember.HasProperty("DateHire"))
                {
                    hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M");
                }
    
                memberId          = currentMember.Id;
    
                if(currentMember.HasProperty("DateHire"))
                { 
                    imageId     = currentMember.GetValue("Image").ToString();
                }
    
                if(currentMember.HasProperty("DateHire"))
                {
                    firstName   = currentMember.GetValue("NameFirst").ToString();
                }
    
                if(currentMember.HasProperty("DateHire"))
                {
                   middleName  = currentMember.GetValue("NameMiddle").ToString(); 
                }
    
                if(currentMember.HasProperty("DateHire"))
                {
                    lastName    = currentMember.GetValue("NameLast").ToString();
                }
    
                if(String.IsNullOrEmpty(imageId))
                {
                    Int32.TryParse(imageId, out outImageId);
                    if(outImageId > 0)
                    {
                        media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId);
                        imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png";
                    }
                }
    
                DateTime currentDateTime = DateTime.Now;
                DateTime outAnniversary = new DateTime();
                string anniversary;
    
                if(currentMember.HasProperty("DateHire"))
                {
                    hireDate = currentMember.GetValue("DateHire").ToString();
                }
                if(currentMember.HasProperty("anniversary"))
                {
                    anniversary = currentMember.GetValue("anniversary").ToString();
                    DateTime.TryParse(anniversary, out outAnniversary);
                }    
                if (currentDateTime.Day == outAnniversary.Day) 
                { 
                    <p>Today!</p> 
                }
    
                else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
                {
                    <p>Going to happen</p>
                }
    
                 else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
                {
                    <p>Has happend</p>
                }
            }
    
  • Charles Afford 1163 posts 1709 karma points
    Jan 11, 2015 @ 15:50
    Charles Afford
    0

    Hello,

    Could you show me what is being rendered and i will help you out with the problem :).

    Also you have a lot of conditional logic in your view which you should not have.

    If

    elseif

    elseif

    You should either use a switch statement or abstract it into a method in a class file and then call the method on your class :).

    So write some code in c# compile it put it in the bin folder of you web site call the method and get the result :).

    Charlie.

  • Daniel Larsen 116 posts 381 karma points
    Jan 12, 2015 @ 09:11
    Daniel Larsen
    1

    Hi, thank you for helping me! :-D

    This is rendered:

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService; IEnumerable members = memberService.GetAllMembers(); string hireDate; int memberId; IMedia media; string imageId = String.Empty; int outImageId; string imageUrl; string firstName; string middleName; string lastName; foreach (IMember currentMember in members) { if(currentMember.HasProperty("DateHire")) { hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M"); } memberId = currentMember.Id; if(currentMember.HasProperty("DateHire")) { imageId = currentMember.GetValue("Image").ToString(); } if(currentMember.HasProperty("DateHire")) { firstName = currentMember.GetValue("NameFirst").ToString(); } if(currentMember.HasProperty("DateHire")) { middleName = currentMember.GetValue("NameMiddle").ToString(); } if(currentMember.HasProperty("DateHire")) { lastName = currentMember.GetValue("NameLast").ToString(); } if(String.IsNullOrEmpty(imageId)) { Int32.TryParse(imageId, out outImageId); if(outImageId > 0) { media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId); imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png"; } } DateTime currentDateTime = DateTime.Now; DateTime outAnniversary = new DateTime(); string anniversary; if(currentMember.HasProperty("DateHire")) { hireDate = currentMember.GetValue("DateHire").ToString(); } if(currentMember.HasProperty("anniversary")) { anniversary = currentMember.GetValue("anniversary").ToString(); DateTime.TryParse(anniversary, out outAnniversary); } if (currentDateTime.Day == outAnniversary.Day) { Today!

    } else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0) { Going to happen

    } else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0) { Has happend

    } }

    Thank you! I owe you a cup of coffee, when this is done ;-)

  • Charles Afford 1163 posts 1709 karma points
    Jan 12, 2015 @ 22:40
    Charles Afford
    0

    Ha no worries all in a days work will look now :)

  • Charles Afford 1163 posts 1709 karma points
    Jan 12, 2015 @ 22:42
    Charles Afford
    0

    Are you using umbraco 7 btw? Is there any reason for @inherits umbraco.MacroEngines.DynamicNodeContext

  • Charles Afford 1163 posts 1709 karma points
    Jan 12, 2015 @ 22:55
    Charles Afford
    0

    @using System.Collections @using Umbraco.Core.Models @using Umbraco.Core.Persistence @inherits umbraco.MacroEngines.DynamicNodeContext @{

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService;
    IEnumerable members = memberService.GetAllMembers(); 
    string hireDate = String.Empty; 
    int memberId = 0;
    string imageId = String.Empty;
    string imageUrl = String.Empty; 
    string firstName = String.Empty; 
    string middleName = String.Empty; 
    string lastName = String.Empty;
    
    foreach (IMember currentMember in members)
        {
            if(currentMember.HasProperty("DateHire"))
            {
                hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M");
            }
    
            memberId  = currentMember.Id;
    
            if(currentMember.HasProperty("DateHire"))
            {
                imageId     = currentMember.GetValue("Image").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
                firstName   = currentMember.GetValue("NameFirst").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
               middleName  = currentMember.GetValue("NameMiddle").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
                lastName    = currentMember.GetValue("NameLast").ToString();
            }
    
            if(String.IsNullOrEmpty(imageId))
            {
                int outImageId;
                Int32.TryParse(imageId, out outImageId);
                if(outImageId > 0)
                {
                    IMedia media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId);
                    imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png";
                }
            }
    
            DateTime currentDateTime = DateTime.Now;
            DateTime outAnniversary = new DateTime();
    
            if(currentMember.HasProperty("DateHire"))
            {
                hireDate = currentMember.GetValue("DateHire").ToString();
            }
            if(currentMember.HasProperty("anniversary"))
            {
                string anniversary = currentMember.GetValue("anniversary").ToString();
                DateTime.TryParse(anniversary, out outAnniversary);
            }
            if (currentDateTime.Day == outAnniversary.Day)
            {
                <p>Today!</p>
            }
    
            else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
            {
    

    Going to happen

            }
    
             else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
            {
    

    Has happend

            }
        }
    <p>@hireDate</p>
    <p>@memberId</p>
    <p>@firstName</p>
    <p>@middleName</p>
    <p>@lastName</p>
    <img src="@imageUrl">@imageId<img/>
    
  • Charles Afford 1163 posts 1709 karma points
    Jan 12, 2015 @ 22:59
    Charles Afford
    0

    If its ok can you mark me as solved please ;)

    Thanks,

    Charlie

  • Daniel Larsen 116 posts 381 karma points
    Jan 13, 2015 @ 08:53
    Daniel Larsen
    0

    Hi, thank you champ!

    I will mark it as solved, when it is solved, but unfortunatly there is still an error.

    When saving the macroscript, I get this error:

    Saving scripting file failed: c:\path-to-umbraco\MacroScripts\635567357154114802_ModuleAnniversary2.cshtml(8): error CS1526: A new expression requires (), [], or {} after type

    I tried adding () a few places in line 8 (Umbraco.Core.Servic...), but no luck.

    Again, thank you for your help. It is much appreciated :-)

  • Daniel Larsen 116 posts 381 karma points
    Jan 13, 2015 @ 09:12
    Daniel Larsen
    0
    @using System.Collections 
    @using Umbraco.Core.Models 
    @using Umbraco.Core.Persistence 
    @inherits umbraco.MacroEngines.DynamicNodeContext 
    
    @{
    
        Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService;
        IEnumerable members = memberService.GetAllMembers(); 
    
        string hireDate = String.Empty; 
        int memberId = 0;
        string imageId = String.Empty;
        string imageUrl = String.Empty; 
        string firstName = String.Empty; 
        string middleName = String.Empty; 
        string lastName = String.Empty;
    
        foreach (IMember currentMember in members)
        {
            if(currentMember.HasProperty("DateHire"))
            {
                hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M");
            }
    
            memberId  = currentMember.Id;
    
            if(currentMember.HasProperty("DateHire"))
            {
                imageId     = currentMember.GetValue("Image").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
                firstName   = currentMember.GetValue("NameFirst").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
               middleName  = currentMember.GetValue("NameMiddle").ToString();
            }
    
            if(currentMember.HasProperty("DateHire"))
            {
                lastName    = currentMember.GetValue("NameLast").ToString();
            }
    
            if(String.IsNullOrEmpty(imageId))
            {
                int outImageId;
                Int32.TryParse(imageId, out outImageId);
                if(outImageId > 0)
                {
                    IMedia media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId);
                    imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png";
                }
            }
    
            DateTime currentDateTime = DateTime.Now;
            DateTime outAnniversary = new DateTime();
    
            if(currentMember.HasProperty("DateHire"))
            {
                hireDate = currentMember.GetValue("DateHire").ToString();
            }
            if(currentMember.HasProperty("anniversary"))
            {
                string anniversary = currentMember.GetValue("anniversary").ToString();
                DateTime.TryParse(anniversary, out outAnniversary);
            }
            if (currentDateTime.Day == outAnniversary.Day)
            {
                <p>Today!</p>
                <p>@firstName</p>
            }
    
            else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
            {
                <p>Going to happen</p>
                <p>@firstName</p>
    
            }
    
             else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
            {
                <p>Has happend</p>
                <p>@firstName</p>
    
            }
        }
    }
    
  • Charles Afford 1163 posts 1709 karma points
    Jan 13, 2015 @ 21:37
    Charles Afford
    0

    Its this line by the looks of it

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService;

    Should be

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService();

    Charlie :)

  • Daniel Larsen 116 posts 381 karma points
    Jan 14, 2015 @ 08:30
    Daniel Larsen
    0

    I already tried that and I get this error message:

    error CS1729: 'Umbraco.Core.Services.MemberService' does not contain a constructor that takes 0 arguments
    

    Thank you again!

    Daniel :-)

  • Charles Afford 1163 posts 1709 karma points
    Jan 14, 2015 @ 21:40
    Charles Afford
    0

    Hi,

    Ok change this line:

    Umbraco.Core.Services.MemberService memberService = new Umbraco.Core.Services.MemberService;

    With this

    IMemberService memberService = ApplicationContext.Current.Services.MemberService;

  • Daniel Larsen 116 posts 381 karma points
    Jan 15, 2015 @ 08:33
    Daniel Larsen
    0

    Success! It saved without errors.

    I added some members with the hireDate of today, but they dont show up on the website. Nothing is rendered. :-/

    I hope this will be the last thing :-)

    Thank you again! :-)

    Daniel

  • Charles Afford 1163 posts 1709 karma points
    Jan 17, 2015 @ 12:00
    Charles Afford
    0

    Hi Daniel,

    You really need an IDE like Visual Studio http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

    You will then be able to see some basic errors. Its hard with out debugging.

    My suggestion would be to post the alias of the property you want to render.

    On the doctype for the node there will be properties. Could you post the properties it has.

    * INSERT In the code under the foreach() *

    @currentMember.Id

    Is this code being run on the correct page?

    Charlie

  • Daniel Larsen 116 posts 381 karma points
    Jan 19, 2015 @ 09:32
    Daniel Larsen
    0

    Hi Charlie

    I think i found the part, where it goes wrong.

    if(currentMember.HasProperty("anniversary"))
            {
                string anniversary = currentMember.GetValue("anniversary").ToString();
                DateTime.TryParse(anniversary, out outAnniversary);
            }
    
            @hireDate <br>
            @outAnniversary <br>
    

    This is being rendered:

    15-01-2014 00:00:00 <br>
    01-01-0001 00:00:00 <br>
    
    02-01-2013 00:00:00 <br>
    01-01-0001 00:00:00 <br>
    
    28-01-2015 00:00:00 <br>
    01-01-0001 00:00:00 <br>
    
    23-09-2014 00:00:00 <br>
    01-01-0001 00:00:00 <br>
    

    What is it you are trying to do in this part? The members does not have a property called anniversary. I calculate everything from the DateHire property. The other properties are rendered properly.

    Thank you for your help. It is much appreciated! :-)

    Daniel

  • Charles Afford 1163 posts 1709 karma points
    Jan 22, 2015 @ 21:19
    Charles Afford
    0

    Hi Daniel sorry for the late reply been busy.

    I was just following your code :')

  • Charles Afford 1163 posts 1709 karma points
    Jan 22, 2015 @ 21:22
    Charles Afford
    0

    What data are you trying to render?

    What do you want to see on the front end?

    Re:anniversary, you had this in your code at the beginning ;)

    You had this in your code originally:

    if(currentMember.HasProperty("anniversary")) { anniversary = currentMember.GetValue("anniversary").ToString(); DateTime.TryParse(anniversary, out outAnniversary); }
    if (currentDateTime.Day == outAnniversary.Day) {

    Today!

    }

    Charlie :)

  • Daniel Larsen 116 posts 381 karma points
    Jan 22, 2015 @ 21:33
    Daniel Larsen
    0

    Hi :-)

    I am sorry to say that it was not in my original code, but in the code you posted. I am writing from my iPad, so I am not sure I can see the whole code, but it does not look like it is there.

    Can I comment it out or is it important for the functionality? Then I will try that tomorrow :-)

    Thank you! :-)

    Daniel

  • Charles Afford 1163 posts 1709 karma points
    Jan 22, 2015 @ 21:46
    Charles Afford
    0

    Looks like i have put it in there not sure why. Sorry about that :'). Let me know what you are trying to render and we will do it :). Nearly there :D

  • Daniel Larsen 116 posts 381 karma points
    Jan 23, 2015 @ 09:25
    Daniel Larsen
    0

    I tried to remove the before mentioned code and tried to correct the remaining code, and it failed miserably! :-)

    It is this part, I am trying to get to work:

    if (currentDateTime.Day == outAnniversary.Day)
            {
                <p>Today!</p>
                @currentMember.Id
            }
    
            else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
            {
                <p>Going to happen</p>
                @currentMember.Id
    
            }
    
             else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
            {
                <p>Has happend</p>
                @currentMember.Id
    
            }
    

    So we are back at my original question. How to compare dates, so that i can show todays anniversary and anniversaries which are +- 14 days :-)

    Thank you for your help! :-)

  • Charles Afford 1163 posts 1709 karma points
    Jan 25, 2015 @ 19:45
    Charles Afford
    0

    Hi,

    Could you tell me what the value of the following are:

    @currentDateTime @outAnniversary @currentDateTime - outAnniversary.TotalDays

    Can you also create a member with an anniversary that is with 14 days :). I think its not working because the conditions are not being met :).

    Thanks,

    Charlie :)

  • Daniel Larsen 116 posts 381 karma points
    Jan 26, 2015 @ 10:22
    Daniel Larsen
    0

    Hi,

    I uploaded the website to this location: http://charlie.dlarsen.dk

    You can login to umbraco with user: charlie and password: isawesome

    Frontend login: akh and 1234

    Then you can poke around the code and maybe find a solution. :-)

    The result is shown to the right on every page.

    The code is in the file: developer > scriptingfile > moduleanniversary2

    Thank you for your help! You are awesome!

    Daniel

  • Daniel Larsen 116 posts 381 karma points
    Feb 09, 2015 @ 09:57
    Daniel Larsen
    0

    Hi Charlie

    I looked at you changes and it sort of works. The problem comes next year. Then the anniversary should show again, preferably with the number of years, the person has been hired.

    Example: This year, Daniel has 1 year anniversary.

    Next year, Daniel has 2 year anniversary.

    Etc.

    I hope it makes sense :-)

    Thank you!

    Daniel

Please Sign in or register to post replies

Write your reply to:

Draft