web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to convert Time into decimal?

(0) ShareShare
ReportReport
Posted on by 433

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

I have the same question (0)
  • Mahesh U Profile Picture
    433 on at

    Can any one suggest me how to achieve this?

  • Suggested answer
    Miguel Llorca Gómez Profile Picture
    7,019 User Group Leader on at

    msdn.microsoft.com/.../dd338899.aspx

  • Suggested answer
    Binesh Profile Picture
    7,887 on at

    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);

    MESSAGE(TymStr);

    TymStr := DELCHR(TymStr,'=',':');

    MESSAGE(TymStr);

    EVALUATE(Result,TymStr);

    MESSAGE(FORMAT(Result));

    //Where as

    //TymStr is a Text Local Variable

  • Verified answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi Mahesh U,

    EVALUATE(gDec_Value, FORMAT(gTim_Value, 0, '<Hours24,2><Minutes,2>'));

    gDec_Value := gDec_Value / 100;

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    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));

  • Community Member Profile Picture
    on at

    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?

  • Suggested answer
    Jens Glathe Profile Picture
    6,092 on at

    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).

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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans