Forum Discussion

AustinK's avatar
AustinK
Qrew Commander
6 years ago

Re: Calculate Daylight Savings time

var date secondsunday = LastDayOfWeek($firstdayofmarch)+Days(1);

That made it calculate that date correctly for me in 2020 but it will no longer calculate correctly for 2019 or probably other years either. So if the record was created after 3/8/2020 it will state it is daylight savings time. If not, it says no. Again just to be sure you saw, your November Sunday is also calculating wrong for 2020.

There may be another solution that will actually calculate for all/most years correctly. I think it is going to be tough to do though.

3 Replies

  • RajHelaiya's avatar
    RajHelaiya
    Qrew Captain
    Yeah, I guess I should be looking at resolving this for all years. Thanks for the quick update. If you can think of a better solution, do let me know.

    ------------------------------
    Raj Helaiya
    ------------------------------
    • AustinK's avatar
      AustinK
      Qrew Commander
      This is a really tough one to crack but I feel like I am getting closer. I tried earlier but was not able to figure out the calculation for the first Sunday of November. Second Sunday of March is easy enough. Look at this post and go over the rules for daylight savings time it gives and that should help.

      https://stackoverflow.com/questions/5590429/calculating-daylight-saving-time-from-only-date/5590518-


      You can try this formula. It isn't fully done but I feel like it is almost there. Let me know if you can improve it and it works for you. There may be parts that are not needed in here, just what I put together earlier before stopping. Feels strange giving out something that may or may not work and need to be fixed, but here it is.

      The biggest issue with this is possibly the first November Sunday. Although it does actually work at least for 2019 and tested it for this year in March. 

      var number myMonth = Month([Created or Now]);
      var number myDay = Day([Created or Now]);
      var number previousSunday = $myDay - DayOfWeek([Created or Now]);

      If($myMonth < 3 or $myMonth > 11, "No",
      $myMonth >= 3 and $myMonth <= 11,
      If(
      $myMonth = 3 and $previousSunday >= 8, "Yes",
      $myMonth = 11 and $myDay > 7, "No",
      $myMonth = 11 and $previousSunday <= 0, "Yes", "No"
      ), "No"
      )

      My "Created or Now" field is this:

      If(
      IsNull([Date Created]), ToDate(Now()), ToDate([Date Created])
      )
      • RajHelaiya's avatar
        RajHelaiya
        Qrew Captain
        Thanks Austin, I will try this and let you know.

        ------------------------------
        Raj Helaiya
        ------------------------------