How to create a function like TIME2DEC

bartwyckmans
Member Posts: 39
I want to convert a time value to a decimal value...
any suggestions?
any suggestions?
0
Comments
-
I think the psuedocode would look like this:
using '12:05:10 AM'
4 variables, for hour, minute, second and the AM/PM are filled with the 4 values
use the EVALUATE function to make sure you get numeric numbers (not text) for the first 3.
If PM, add 12 to the hour variable.
Then, what do you want? A total number of seconds? This would be easy, multiple the minutes by 60 and the hours by 3600, then add them all together.
If you want minutes multiply the hours by 60 and divide the seconds by 60 and add them all together.
-a0 -
thank you but i mean it in the other direction
you have a variable with a time value in it.
timeVar := 10:20:00
i want to get the decimal value
in this way
decimalVar = 10,20
so you can you convert that timeVar into a DecimalVar
hope you can handle that problem.0 -
No, that is what I meant.
Basically you have to turn each part of your time value (which you can turn into a string using FORMAT), into a separate number and use this for a number.
tTime := FORMAT(10:20:00)
dHour := StrToInt(copy(tTime, 1, 2))
dMinute := StrToInt(copy(tTime, 3, 2))
dSecond := StrToInt(Copy(tTime, 5, 2))
dResult := dHour + (dMinute / 60) + (dSecond / 3600)
I didn't check this, just wrote it off the top of my head.0 -
I am very very sorry
but it doesn't work.
It isn't possible to use the function StrToInt bcs it is not useable in Navision. So I try to use the functions EVALUATE, STRSUBSTNO, FORMAT to change the type of the timevalue into a stringformat. but none off them works!
he always gives an error that typeconversion is not possible from Time to Text.
Must that be possible I can follow your syntax to spilt it up in hours, minutes and seconds.
hope you have an other suggestion0 -
If you subtract two C/AL Time variables, you get an Integer that contains the number of milliseconds between the two Times. So, you can use the following code to go from a Time to a Decimal:
// convert time to milliseconds... intMilliSecondsSinceMidnight := MyTime - 000000T; // throw away seconds and milliseconds... intMinutesSinceMidnight := ROUND(intMilliSecondsSinceMidnight,1000*60); // convert to decimal hours (minutes represented as decimal fraction) decHours := intMinutesSinceMidnight / 60;
0 -
thank you this code is very useful !0
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