fmpdude

Get Last Friday Of Year

Discussion created by fmpdude on Jan 1, 2017
Latest reply on Jan 3, 2017 by fmpdude

I had a need to know when the last Friday of the year was so I could dynamically update a label.


Below is the LET function I created and wanted to share it in case it might help someone else.

 

The basic idea is to compute the offset from the end of the year. I realize there are other ways to do this, possibly easier, but this is how I did it.


(Tested this logic with the following test cases, but there could still be a bug:

 

Date(12 ; 31 ; 2013 ) - mod (DayOfWeek(Date(12 ;31 ; 2013)+1) ; 7) = 12/27/2013

Date(12 ; 31 ; 2014 ) - mod (DayOfWeek(Date(12 ;31 ; 2014 )+1) ; 7) = 12/26/2014

Date(12 ; 31 ; 2015 ) - mod (DayOfWeek(Date(12 ;31 ; 2015 )+1) ; 7) = 12/25/2015

Date(12 ; 31 ; 2016 ) - mod (DayOfWeek(Date(12 ;31 ; 2016 )+1) ; 7) = 12/30/2016

Date(12 ; 31 ; 2017 ) - mod (DayOfWeek(Date(12 ;31 ; 2017 )+1) ; 7) = 12/29/2017

Date(12 ; 31 ; 2018 ) - mod (DayOfWeek(Date(12 ;31 ; 2018 )+1) ; 7) = 12/28/2018

Date(12 ; 31 ; 2019 ) - mod (DayOfWeek(Date(12 ;31 ; 2019 )+1) ; 7)  = 12/27/2019

Date(12 ; 31 ; 2021 ) - mod (DayOfWeek(Date(12 ;31 ; 2021)+1) ; 7)  = 12/31/2021

Date(12 ; 31 ; 2022 ) - mod (DayOfWeek(Date(12 ;31 ; 2022)+1) ; 7)  = 12/30/2022

)

 

------------------

 

LET (

[

   lastFridayOfYear = Date(12 ; 31 ; Year(checkdate) ) - Mod (DayOfWeek(Date(12 ;31 ; Year(checkdate) )+1) ; 7)

] ;

lastFridayOfYear

)

 

Simple but useful.

Outcomes