【问题标题】:Convert ddmmyyy character to DATE将 ddmmyyy 字符转换为 DATE
【发布时间】:2018-09-10 19:48:23
【问题描述】:

如何将 ddmmyyyy 形式的字符转换为 DATE 类型?

有没有格式化字符变量的方法?例如取变量的前两个字符。

【问题讨论】:

    标签: openedge progress-4gl


    【解决方案1】:
    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】:

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多