Does anybody have an idea how to calculate the difference between two dates?
I want to calculate the difference and get the result in form of three variables which will represent years, months, days.
I need this to be able to show how long does an employee work for the company.
That information will be presented in this form: YY-MM-DD
0
Comments
numdays is an integer and Date1 and Date2 are both date variables.
From the number of days you can then calculate the number of years, months and days.
RIS Plus, LLC
If I start with difference in days I'll need to take care of leap years.
What is the result that I need:
Start date: 17.07.2004
End date: 13.02.2007
Difference should be (YY-MM-DD): 02-06-27
So I decided to start this way:
To handle days is a little bit more complicated than what I did to this point, so if somebody has an idea, please drop it here
TNX!
1Y=xM
1M=yD
Because one Month can be 30,31,28,29 days and it has no meaning to calc difference in such a unit...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
http://cs.senecac.on.ca/~tmckenna/bobje ... anCalendar)
I've used these variables and types:
RecDate Record Date
StartDate Date
EndDate Date
TempDate Date
LastFoundDate Date
TotalDays Integer
CountYears Integer
CountMonths Integer
CountDays Integer
Found Boolean
Text001 Total Days: %1\Years: %2\Months: %3\Days: %4
After running this code (with your example dates) I get the message:
Total Days: 942
Years: 2
Months: 6
Days: 27
The count of days per month (28,29,30,31) shouldn't be a problem, because Navision-Table DATE knows ist.
Hope this is helpful.
I don't see how you can come up with a good solution for that. Like Kamil said, since months and even years have different numbers of days, a YY-MM-DD expressed as a number of years plus a number of months plus a number of days would be meaningless without a starting date.
How were you going to address that part?
RIS Plus, LLC
I just need to test it a little bit but I think this is it.
Not so easy, is it?
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
suddenly, DateEnd - DateStart is giving me 0. (31.12.2018-01.12.2018). Don't understand why?
*** FORGET IT- EMOTION -
had a variable with same name as field in a WITH ..DO BEGIN statement.