Progress 4GL中如何将Decimal值转换为日期和时间?
Converting Decimal DATETIME Representation to Date and Time in Progress 4GL
Hey there! That Decimal value you've got looks like Progress's internal representation of a DATETIME type—where the integer part is the number of days since January 1, 1800, and the decimal fraction represents the portion of the day (time). Here's how to split it into separate date and time strings:
Step-by-Step Code Solution
First, we'll convert the Decimal to a proper DATETIME variable, then extract and format the date and time components:
DEFINE VARIABLE tt_decimal AS DECIMAL INIT "2,459,040.7355" . DEFINE VARIABLE tt_date AS CHARACTER. DEFINE VARIABLE tt_time AS CHARACTER. DEFINE VARIABLE tt_datetime AS DATETIME NO-UNDO. /* New variable to hold the datetime */ /* Convert the decimal to a DATETIME */ tt_datetime = DATETIME(tt_decimal). /* Extract and format the date part */ tt_date = STRING(DATE(tt_datetime), "MM/DD/YYYY"). /* Adjust format as needed */ /* Extract and format the time part (includes milliseconds) */ tt_time = STRING(TIME(tt_datetime), "HH:MM:SS.FFF").
How It Works
DATETIME(tt_decimal): Converts your Decimal value into a native ProgressDATETIMEtype, which combines both date and time.DATE(tt_datetime): Pulls just the date component from theDATETIMEvalue (this is an integer representing days since 1800-01-01).STRING(..., "MM/DD/YYYY"): Formats the date into a human-readable string. You can change the format to match your needs—examples include:"DD/MM/YYYY"for day-month-year order"YYYY-MM-DD"for ISO standard format"Mon DD, YYYY"for a more readable format like "Jan 01, 2024"
TIME(tt_datetime): Extracts the time component (an integer representing seconds since midnight).STRING(..., "HH:MM:SS.FFF"): Formats the time to include hours, minutes, seconds, and milliseconds. If you don't need milliseconds, use"HH:MM:SS"instead.
Example Output
For your given value 2,459,040.7355:
tt_datewould be09/02/8537(yes, that's far in the future—your sample value represents over 6700 years since 1800!)tt_timewould be17:39:07.200(since 0.7355 of a day equals ~17 hours, 39 minutes, 7 seconds)
内容的提问来源于stack exchange,提问作者Varun K S
相关产品推荐
相关产品推荐

