如何将ddmmyyyy形式的字符转换为DATE类型?
是否存在格式化字符变量的方法?例如,取变量的前两个字符。
答案 0 :(得分:4)
define variable s as character no-undo initial "10092018".
define variable d as date no-undo.
d = date( integer( substring( s, 3, 2 )), integer( substring( s, 1, 2 )), integer( substring( s, 5, 4 ))).
display d format "99/99/9999".
答案 1 :(得分:2)
DATE
函数可用于此目的:
DATE ( month, day, year )
或
DATE ( string )
如果您将日期格式设置设置为dmy
,则以下两项均可以使用:
define variable cDate as character no-undo.
define variable dDate1 as date no-undo.
define variable dDate2 as date no-undo.
cDate = "31122018".
dDate1 = date(cDate).
dDate2 = date (int(substring(cDate,3,2)) /*month*/,
int(substring(cDate,1,2)) /*day*/,
int(substring(cDate,5)) /*year*/).
display dDate1 dDate2.