Brian Dunning's FileMaker Custom Functions

isDaylightTime ( dt )

Returns 1 or 0 to indicate whether the given date falls within U.S. daylight savings time (post-2007)

  Average rating: 4.3 (30 votes) Log in to vote

Howard Schlossberg   Howard Schlossberg - Show more from this author
FM Professional Solutions
http://fmprosolutions.com

Share on Facebook Share on Twitter

  Sample input:
isDaylightTime ( date( 5; 1; 2014 ) )
  Sample output:
1

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns 1 or 0 to indicate whether the given date falls within U.S. daylight savings time (post-2007)

 

Comments

Scott   Scott, Edmonton, AB
Apr 29, 2015
There is a mistake in the DSTEnd calc., it should be identical to the DSTBegin calc except for the month/day values.

Instead of simply fixing it that way, I made the following modification

dow_oset = floor( mod( 1 + ( yr * 1.25); 7) );
DSTBegin = date( 3 ; 14 ; yr ) - dow_oset;
DSTEnd = date( 11 ; 7 ; yr ) - dow_oset

An interesting detail to note is DST is a constant at 238 days. Therefore DSTEnd can be obtained thusly:

DSTEnd = DSTBegin + 238

Additionally, there is a DayOfWeek function, so the following is equivallent

dow_oset = DayOfWeek(date(3, 1, yr))

Here is the entire rewrite:

Let([
yr = Year(dt);

// DSTBegin is 2nd Sunday of March, minimum is the 8th.
FirstPossibleSunday = Date(3; 8; yr);

// Offset to 2nd Sunday of March
DSTBegin = FirstPossibleSunday + (8 - DayOfWeek(FirstPossibleSunday))
];

Case(
dt < DSTBegin ; 0 ;
dt >= DSTBegin + 238 ; 0 ;
1
)
)
 
Howard Schlossberg   Howard Schlossberg, FM Professional Solutions
Apr 29, 2015
Thanks for your notes, Scott. Yours is certainly easier to understand than mine, which I essentially copied from some forum I found online for some other computer language when I needed a solution for whatever I was working on at the time.

Meanwhile, I've fixed the missing floor() in my calc above, and visitors now have the option of using mine or yours.

Thanks again...
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: