Kaviya
June 17, 2025, 11:40am
1
If today is 2025.06.17, the how to get the past fifth year (2020.06.17) in function. It also includes the leap year and whenever I change the date it has to get the specific date of the fifth year.
Below is the function I have tried. For some of the dates it is not showing the exact value. If there is any better function, please let me know.
Year:{$[(
mm$x)=1;$[(((year$x)-4)mod 4)<>1;x-1826; x-1827];$[(((
year$x)-4)mod 4)>0;x-1826;x-1827]]}[.z.d]`
mwoods
June 17, 2025, 4:50pm
2
Which dates is it not returning what you’d expect? I tried a few test cases and it returns what I’d expect
q)Year 2024.02.29
2019.02.28
q)Year 2024.06.17
2019.06.17
q)Year 2020.06.17
2015.06.17
q)Year 2020.02.29
2015.02.28
Kaviya
June 18, 2025, 6:42am
3
for this date 2025.02.28, I am getting 2020.02.29
jlucid
June 19, 2025, 12:58pm
4
isLeapYear:{((0=x mod 4)&(0<>x mod 100))|(0=x mod 400)}
Year:{[d]
y:`year$d;m:`mm$d;day:`dd$d;
targetYear:y - 5;
adjustedDay: $[(m=2i) & (day=29i) & not isLeapYear[targetYear]; 28i; day];
"D"$"." sv string (targetYear; m; adjustedDay)
}
2020.06.17=Year 2025.06.17
2018.03.15=Year 2023.03.15
2016.12.31=Year 2021.12.31
2019.02.28=Year 2024.02.29
2015.02.28=Year 2020.02.29
1995.02.28=Year 2000.02.29
2020.02.28=Year 2025.02.28
2018.02.28=Year 2023.02.28
2023.02.28=Year 2028.02.29
2020.01.01=Year 2025.01.01
2020.12.31=Year 2025.12.31
2020.03.01=Year 2025.03.01
2020.02.27=Year 2025.02.27
2011.02.28=Year 2016.02.29
2019.02.28=Year 2024.02.28
2019.02.28=Year 2024.02.29
2019.06.17=Year 2024.06.17
2015.06.17=Year 2020.06.17
2015.02.28=Year 2020.02.29