Search code examples
openedgeprogress-4gl4gl

decimal number valued datetime formatting in 4gl


The value of the field is in (deci-5 99999999.99999) format, like: 20201231.65624 where 2020 is year, 12 is month, 31 is date and .65624 is the hour and minute value.

I want to display it like 31/12/2020 18:13.

I mean DD/MM/YY hh:mm like this format. So far, I am able to display only the date part i.e. 31/12/2020. But not able to display the hour and minute part.

Appreciate help on this regards. Thanks.


Solution

  • This will display the time portion in hh:mm:ss if the value is a string:

    display string( integer ( entry( 2, "20201231.65624", "." )), "hh:mm:ss" ).
    

    or, if the value is a decimal:

    define variable d as decimal no-undo initial 20201231.65624.
    
    display string( integer(( d - truncate( d, 0 )) * 100000 ), "hh:mm:ss" ).
    

    Obviously you would want to abstract that approach to fit whatever your real need is.

    The technique of using a character or decimal field to hold a datetime is a legacy of ancient versions of Progress that did not support a DATETIME or DATETIME-TZ datatype. Since OpenEdge 10 you have a native datatype that you should be using for that purpose. This kind of approach with decimals and strings should really only be used for backwards compatibility to old code and old database schemas.