Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...