Converts a value from internal format to external format.
Synopsis
OCONV(istring,code)
Arguments
istring
code
An expression that resolves to a string or integer. It specifies a value represented in internal (storage) format.
A character code, specified as a quoted string, that specifies the type of conversion to perform. Conversion is from internal format to external format.
Description
The OCONV function is a general-purpose conversion function used to convert from internal (storage) format to external (output) format. The type of conversion is specified by a character code string that is specific to the type of data to be converted. Most valid CMQL conversion codes can be used.
The following are the character codes for time and date conversion. If you specify optional code characters for date or time formatting, these characters must be specified in the order described below.
The following are the character codes for string and numeric conversions:
You can use the STATUS function to determine the success of an OCONV conversion.
The OCONV function converts from internal format to external format. The ICONV function converts from external format to internal format. Note that the MCDX/MCXD, MCAX/MCXA, and MCWX/MCXW code pairs have the opposite meanings in ICONV, reversing the OCONV operation.
You can use the OCONVS function to convert the elements of a dynamic array from internal format to external format.
Date Conversion
You can display a date in any of the following formats:
Abbreviated month format (“08 AUG 2006"), with either four-digit years (code "D" or "D4") or two-digit years (code "D2").
Numeric format ("08/08/2006"), with your choice of separator character (code "D/", "D-", etc.) and either four-digit years (code "D/" or "D4/"), two-digit years (code "D2/"), or no year (code "D0/"). The day/month order (American or European) is determined by the current Caché locale.
Note:
You can specify the default date format using Caché NLS. Because of operational differences between MV and Caché NLS in the handling of month names, your NLS default date format must represent months as integers.
You can use the DATE function to supply the current date in internal format. The DATE and TIME functions return internal format values. TheTIMEDATE function returns external format values.
Internal dates are an integer count of days, with 0 representing December 31, 1967. Dates earlier than December 31, 1967 can be represented using negative numbers. The largest permitted internal date is 2933628, which represents December 31, 9999. The smallest permitted internal date is -46385, which represents December 31, 1840.
The expansion of two-digit years to four digits is governed by the MultiValue CENTURY.PIVOT verb, described inOperational Differences Between MultiValue and Caché.
Examples
The following example shows date conversions:
DateConversions: ! Month Abbreviation Formats: PRINT OCONV(0,"D"); ! "31 DEC 1967" PRINT OCONV(14100,"D"); ! "08 AUG 2006" PRINT OCONV(14100,"D2"); ! "08 AUG 06" PRINT OCONV(DATE(),"D"); ! current date in above format PRINT OCONV(@DATE,"D"); ! current date in above format PRINT OCONV(14120,"D-") ! "08-28-2006" PRINT OCONV(14120,"D/") ! "08/28/2006" PRINT OCONV(14120,"DE") ! "28/08/2006" PRINT OCONV(14120,"D2/") ! "08/28/06" PRINT OCONV(14120,"D2-E") ! "28-08-06"
The following example shows time conversions:
TimeConversions: PRINT OCONV(0,"MT") PRINT OCONV(TIME(),"MT") PRINT OCONV(TIME(),"MTH") PRINT OCONV(TIME(),"MTS") PRINT OCONV(TIME(),"MTS.") PRINT OCONV(TIME(),"MTHS*")
The following example shows case conversions:
CaseConversions: mystr="The qUICK BrOwn foX" PRINT OCONV(mystr,"MCU") ! Returns: THE QUICK BROWN FOX PRINT OCONV(mystr,"MCL") ! Returns: the quick brown fox PRINT OCONV(mystr,"MCT") ! Returns: The Quick Brown Fox
The following example shows decimal-to-hex and hex-to-decimal conversions. It shows both the OCONV conversions and the inverse ICONVconversions:
HexConversions: PRINT OCONV(10,"MCXD"); ! Returns 16 PRINT OCONV(10,"MCDX"); ! Returns A PRINT ICONV(10,"MCXD"); ! Returns A PRINT ICONV(10,"MCDX"); ! Returns 16
The following example shows character-to-code and code-to-character conversions. It shows both the OCONV conversions and the inverseICONV conversions:
CharConversions: PRINT OCONV("mnop","MCAX"); ! Returns 6D6E6F70 PRINT OCONV("6D6E6F70","MCXA"); ! Returns mnop PRINT ICONV("mnop","MCXA"); ! Returns 6D6E6F70 PRINT ICONV("6D6E6F70","MCAX"); ! Returns mnop
The following example shows masked decimal conversions with rounding to the specified number of decimal digits, and zero padding when needed:
MaskedDecimalConversions: PRINT OCONV("123.57","MD0"); ! Returns 124 PRINT OCONV("123.57","MD1"); ! Returns 12.4 PRINT OCONV("123.57","MD2"); ! Returns 1.24 PRINT OCONV("123.57","MD3"); ! Returns 0.124 PRINT OCONV("123.57","MD4"); ! Returns 0.0124
The following example shows pattern match extraction. It returns the input string if it matches the specified pattern. These examples perform pattern matches on 7 and 10 digit telephone numbers specified in the following commonly used formats: “123–4567”, "617-123-4567", and "(617) 123-4567":
PatternMatch: PRINT OCONV(telnum,"P(3n-3n-4n)") ! matches and returns 10-digit numbers ! in hyphen format PRINT OCONV(telnum,"P(3n-4n);(3n-3n-4n)") ! matches and returns either 7-digit or 10-digit numbers ! in hyphen format. PRINT OCONV(telnum,"P(3n-3n-4n);('('3n')' 3n-4n)") ! matches and returns 10-digit numbers ! in either hyphen or parentheses formats. PRINT OCONV(telnum,"P('617'-3n-4n);('(617)' 3n-4n)") ! matches and returns 10-digit numbers ! in either hyphen or parentheses formats ! that begin with the 617 area code.
See Also