Time calculation

Asallai
Member Posts: 142
Hi All,
It is possible to calculate Time variable? I mean I'd like to increment a Time field with a variable of Time Type. :?
I've got an error message when I tried to add 2 Time variable. But in this case how can I cumulative two Time field with each other?
Thank you!
It is possible to calculate Time variable? I mean I'd like to increment a Time field with a variable of Time Type. :?
I've got an error message when I tried to add 2 Time variable. But in this case how can I cumulative two Time field with each other?

Thank you!
0
Comments
-
one cannot add two dates because it is meaningless. For example what would it mean to add January 1st 2007 to May 20th 2005 ?
One can only add interval to a date, or subtract an interval from a date.
To get an interval you need to subtract one date from another or specify the interval implicitly in CALCDATE function.0 -
If you want to do something like 5:00:00 + 3:00:00 = 8:00:00 you can use the DateTime type for that. You can transform the time to DateTime with 1.1.0000 date part and add them. Than extract the time part from the DateTime. Do not forget that if you do "23:00:00" + "2:00:00" it will be next day with time "1:00:00".
It means:NewTime := DT2TIME(CREATEDATETIME(0D,MyTime1)+(CREATEDATETIME(0D,MyTime2)-CREATEDATETIME(0D,0T)))
1 -
Thanks a lot kine, I've searched this
Eugene, thanks you too.0 -
Why this sentence shows an error??:
"Type conversion is not possible because 1 of the operators contains an invalid type"VarDatetime := CREATEDATETIME(Capacity."Ending Date",Capacity."Ending Time") + CREATEDATETIME(0D,030000T); // Add 3 Hours
0 -
Because you need to add just duration, not another datetime. In the example there is DateTime+(DateTime-DateTime) which means DateTime+Duration. It is why there is the part "-CREATEDATETIME(0D,0T)" - to convert DateTime to duration.. ;-) it is a little tricky...0
-
My suggestion is simple. Use variable of type Duration (represent the difference between two datetimes, in milliseconds.) to calculate time.
// 03:20 = (3 * 60 minutes) + 20 minutes = 200 minutes
// 200 minutes = 200 * 60 seconds = 12 000 seconds
// 12 000 seconds = 12 000 * 1000 milliseconds = 12 000 000 milliseconds
varInteger := (3 * 60 + 20) * 60 * 1000; // desired time specified in milliseconds.
varDuration := var varInteger;
varTime := 0000T + varDuration;
MESSAGE(FORMAT(varTime)); // result is 03:20:00
So simply add some duration period in milliseconds to zero time and calculating a new time.
Thank's !!!
Devendra Sharma0
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