Hi all,
i need to convert a time into decimal. How to achieve this?
Ex:- 1:34:00AM(Time variable) Need to convert as 1.34(Decimal).
Thanks in Advance.
Mahesh U.
*This post is locked for comments
The "old" production AddOns did this kind of trick: They converted all times to decimal, with 1 hour = 3.600, 1 second = 0.001. I have used this for timezone-based calculations a long time ago. Like this:
DatetimeTZ(Date : Date;Time : Time;TimeZoneCode : Code[10]) : Decimal //Create DateTime(Decimal) in UTC with respect to the time zone shift IF (Date = 0D) THEN EXIT(0); L_TZDiff:=GetTZOffset(Date,Time,TimeZoneCode); IF Time = 0T THEN EXIT((Date-01010000D) * 86.400 - L_TZDiff*3.600) ELSE EXIT(((Date-01010000D) * 86.400) + (Time - 000000T)/1000000 - L_TZDiff*3.600);
The nice part regarding the decimals is that you can simply add and multiply these values, and also convert them back to a real date, even when you cross a date (duration crosses a date border).
Do you mean 'decimal' to mean just replacing the colon with a period? Search and replace?
Or do you mean doing the math to convert 34 minutes out of a 60 minute hour to be equal to .57 of an hour, giving 1.57 in your example?
Do you also want to incorporate a 24 hour format to account for AM vs PM? 1.57 being different than 13.57 for 1:34PM?
Or do you want to convert 1.57 hours out of a 24 hour day giving you .06541666... of a day?
What are you attempting to accomplish with the conversion?
use following code:
// variables
timeVal Time
decVal Decimal
strVal Text
// the code
timeVal := 013400T;
strVal := COPYSTR(FORMAT(timeVal),1,5); // get first 5 digits incl. : seperator
strVal := CONVERTSTR(strVal,':',','); // replace : by , or . acc. to your regional setting.
EVALUATE(decVal,strVal); // convert to dec. value
MESSAGE(FORMAT(decVal));
Hi Mahesh U,
EVALUATE(gDec_Value, FORMAT(gTim_Value, 0, '<Hours24,2><Minutes,2>'));
gDec_Value := gDec_Value / 100;
Hi! Mahesh Use This Function or Code According to ur requirements.
LOCAL TimeToDecimal(TimeP : Time) Result : Decimal
TymStr := FORMAT(TimeP);
MESSAGE(TymStr);
TymStr := DELSTR(TymStr,(STRLEN(TymStr)-1),2);
TymStr := DELCHR(TymStr,'=',':');
EVALUATE(Result,TymStr);
MESSAGE(FORMAT(Result));
//Where as
//TymStr is a Text Local Variable
msdn.microsoft.com/.../dd338899.aspx
Can any one suggest me how to achieve this?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.