代码之家  ›  专栏  ›  技术社区  ›  sander

将ddmmyyy字符转换为日期

  •  0
  • sander  · 技术社区  · 7 年前

    2 回复  |  直到 7 年前
        1
  •  4
  •   Tom Bascom    7 年前
    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".
    
        2
  •  2
  •   Arno van der Ende    7 年前

    这个 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.