Good thinking Thomas, we should think .net these days.
True, but in this case it seems to me that using .net to determine if a year is a leap year is a bit overkill and more using the technology for the sake of having used the technology......
It is as when the Americans met the Russians for the first time in space : The US had invested millions in making a pen with a pressurized ink cartridge so it would write in zero gravity. When they asked the russians how they solved that particular problem, the Russians answered : "we just use pencils".
[edit] To add yet another way to determine the leap year : Check the date table if February 29th exists for that year.
TheYear := 2012;
Date.GET(Date."Period Type"::Month,DMY2DATE(1,2,TheYear));
IF DATE2DMY(NORMALDATE(Date."Period End"),1) = 29 THEN
MESSAGE('Year %1 is a leap year',TheYear);
I have won many a beer on a debate when year is a leap year.
A leap year is a year that can be divided by 4 unless it can be divided by 100 and again if it can be divided by 400.
So 1700, 1800, 1900 was not a leap year, but 2000 was, and 2100 will not be a leap year.
And for calculation in practice then do take some .net class that can calculate it as many suggest or your AL code. If date between February 28 <year> to March 1 <year> is equal to 2 then a leap year otherwise not.
Eric Beran
Software Design Engineer II Dynamics NAV Office 365 Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
I have won many a beer on a debate when year is a leap year.
A leap year is a year that can be divided by 4 unless it can be divided by 100 and again if it can be divided by 400.
So 1700, 1800, 1900 was not a leap year, but 2000 was, and 2100 will not be a leap year.
Me too
But I'll need to pay as much beer if my software still runs in 2100. Because year 2000 can be devided by 400 I sometimes tend to just divide by 4. I know this is not accurate but I believe it's sufficient for the scope of my code.
Here's another solution:
IF DATE2DMY(CALCDATE('<CM>',DMY2DATE(1,2,MyYear)),1) = 29 THEN
LeapYear := TRUE;
"Money is likewise the greatest chance and the greatest scourge of mankind."
This discussion shows (to me at least) that normally you are better off using a built in function, in this case the .NET. Of course .NET function could be wrong, but I trust it's not...
Thomas
Comments
ex: 2014 MOD 4 = 2 means not a leap year
2016 MOD 4 = 0 means Leap year.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
(Simultaneous posting :oops: )
How about use a .NET Class for this?
Thomas
http://msdn.microsoft.com/en-us/library ... r(v=vs.110).aspx
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
And IMO at least as important: We should not re-invent the wheel, this was the reason for my first answer.
Regards
Thomas
True, but in this case it seems to me that using .net to determine if a year is a leap year is a bit overkill and more using the technology for the sake of having used the technology......
It is as when the Americans met the Russians for the first time in space : The US had invested millions in making a pen with a pressurized ink cartridge so it would write in zero gravity. When they asked the russians how they solved that particular problem, the Russians answered : "we just use pencils".
[edit] To add yet another way to determine the leap year : Check the date table if February 29th exists for that year.
BTW: Mark, your link does not work. This is the correct link : http://msdn.microsoft.com/en-us/library/system.datetime.isleapyear(v=vs.110).aspx
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
A leap year is a year that can be divided by 4 unless it can be divided by 100 and again if it can be divided by 400.
So 1700, 1800, 1900 was not a leap year, but 2000 was, and 2100 will not be a leap year.
And for calculation in practice then do take some .net class that can calculate it as many suggest or your AL code. If date between February 28 <year> to March 1 <year> is equal to 2 then a leap year otherwise not.
Software Design Engineer II
Dynamics NAV Office 365
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
But I'll need to pay as much beer if my software still runs in 2100. Because year 2000 can be devided by 400 I sometimes tend to just divide by 4. I know this is not accurate but I believe it's sufficient for the scope of my code.
Here's another solution:
Thomas
This will not work, as 1700, 1800, 1900 and 2100 eg. are not leap years.
BR Per
:thumbsup: