How to calculate leap year

mistu2020
Member Posts: 15
I want to calculate no of days.
If leap year then the no of days will be 366 other wise 365.
How to do this????
If leap year then the no of days will be 366 other wise 365.
How to do this????
0
Comments
-
If year MOD 4 = 0 then leap year
ex: 2014 MOD 4 = 2 means not a leap year
2016 MOD 4 = 0 means Leap year.0 -
0
-
Another alternative:
NoOfDays := DMY2DATE(31,12,Year) - DMY2DATE(31,12,Year - 1);
(Simultaneous posting :oops: )* Daniele Rebussi * | * Rebu NAV Diary *0 -
You can also use the virtual date table. Count the days in a year. It's an in memory process, should be fast.0
-
Just curiuos:
How about use a .NET Class for this?
Thomas0 -
Good thinking Thomas, we should think .net these days.
http://msdn.microsoft.com/en-us/library ... r(v=vs.110).aspx0 -
Mark Brummel wrote:Good thinking Thomas, we should think .net these days.0
-
Mark Brummel wrote:Good thinking Thomas, we should think .net these days.
And IMO at least as important: We should not re-invent the wheel, this was the reason for my first answer.
Regards
Thomas0 -
Mark Brummel wrote: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.0 -
And this is pure Russian-style C/AL 8) :
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);
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).aspxRegards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
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.0 -
beran wrote: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.
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."0 -
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...
Thomas0 -
To be honest, the creation of the Date table is also a built-in function. So, I would trust it also."Money is likewise the greatest chance and the greatest scourge of mankind."0
-
mohana_cse06 wrote:If year MOD 4 = 0 then leap year
ex: 2014 MOD 4 = 2 means not a leap year
2016 MOD 4 = 0 means Leap year.
This will not work, as 1700, 1800, 1900 and 2100 eg. are not leap years.
BR Per0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions