如何将日期格式化为 DD、月、年?

发布于 2024-08-08 10:52:39 字数 179 浏览 7 评论 0原文

我需要像

20091101 --> "01", "november", "2009"

“01”和“2009”一样分割ABAP日期,但是如何获取月份名称(应该本地化)?

有一个函数可以做到这一点吗?

如果没有这样的功能,也许是一个带有月份名称的表?

I need to split ABAP date like

20091101 --> "01", "november", "2009"

The "01" and "2009" are trivial, but how do I get the month name (which should be localized)?

Is there a function to do that?

If there is no such function, perhaps a table with month names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

白况 2024-08-15 10:52:39

您可以使用模块函数“MONTH_NAMES_GET”获取给定语言的月份名称,并将语言作为参数传递。还可以使用“RH_GET_DATE_DAYNAME”获取日期(例如星期日)

Guillaume

You can get the month's name in a given language using the module function 'MONTH_NAMES_GET', passing the language as a parameter. The day (Sunday for example) can also be obtained using 'RH_GET_DATE_DAYNAME'

Guillaume

灰色世界里的红玫瑰 2024-08-15 10:52:39

我认为最简单的方法是将转换退出 LDATE 应用到您的日期字段。最简单的是调用函数模块CONVERSION_EXIT_LDATE_OUTPUT。

例如,这将转换

20090101

01. January 2009

(除非您实际上需要将日期、月份文本和年份放在单独的字符串中,您似乎已表明这一点。无论如何,也许它会对其他人有所帮助)。

I think the absolute simplest way would be to apply the conversion exit LDATE to your date field. Easiest is to call function module CONVERSION_EXIT_LDATE_OUTPUT.

This would for example convert

20090101

to

01. January 2009

(Unless you need to actually have the day, month text and year in separate strings, which you seem to indicate. Anyway, maybe it will help someone else).

故事未完 2024-08-15 10:52:39

此代码将为您提供长文本格式的日期,例如“2011 年 12 月 2 日”。您可以相应地更改代码以打印具有长月份名称的日期。

DATA: LONG_DATE(20).
PERFORM GET_LONG_DATE USING LONG_DATE.
WRITE: LONG_DATE.

FORM GET_LONG_DATE USING DATE.

DATA: T_MONTH_NAMES LIKE TABLE OF T247 WITH HEADER LINE.

CALL FUNCTION 'MONTH_NAMES_GET'
 EXPORTING
   LANGUAGE     = SY-LANGU
  TABLES
    MONTH_NAMES = T_MONTH_NAMES
  .

DATA: YEAR(4)   TYPE C,
      MONTH(2)  TYPE C,
      DAY(2)    TYPE C.

YEAR = SY-DATUM+(4).
MONTH = SY-DATUM+4(2).
DAY = SY-DATUM+6(2).


READ TABLE T_MONTH_NAMES INDEX ( MONTH ).

CONCATENATE T_MONTH_NAMES-LTX ' ' DAY  INTO DATE SEPARATED BY SPACE.
CONCATENATE DATE ',' INTO DATE.
CONCATENATE DATE YEAR INTO DATE SEPARATED BY SPACE.

WRITE / DATE.

ENDFORM.

This code will give you the date in the long text format like 'December 02, 2011'. You may change the code accordingly to print the date with long MONTH name.

DATA: LONG_DATE(20).
PERFORM GET_LONG_DATE USING LONG_DATE.
WRITE: LONG_DATE.

FORM GET_LONG_DATE USING DATE.

DATA: T_MONTH_NAMES LIKE TABLE OF T247 WITH HEADER LINE.

CALL FUNCTION 'MONTH_NAMES_GET'
 EXPORTING
   LANGUAGE     = SY-LANGU
  TABLES
    MONTH_NAMES = T_MONTH_NAMES
  .

DATA: YEAR(4)   TYPE C,
      MONTH(2)  TYPE C,
      DAY(2)    TYPE C.

YEAR = SY-DATUM+(4).
MONTH = SY-DATUM+4(2).
DAY = SY-DATUM+6(2).


READ TABLE T_MONTH_NAMES INDEX ( MONTH ).

CONCATENATE T_MONTH_NAMES-LTX ' ' DAY  INTO DATE SEPARATED BY SPACE.
CONCATENATE DATE ',' INTO DATE.
CONCATENATE DATE YEAR INTO DATE SEPARATED BY SPACE.

WRITE / DATE.

ENDFORM.
So要识趣 2024-08-15 10:52:39
* to get full name of the day / month also can use


          GET_MONTH_NAME ... for month and 
            GET_DATE_DAYNAME for the specific day name too

获取其他格式日期的其他方法有

  • 使用 WRITE 语句

     数据:get_date(10)。 “存储输出日期的字段
    
    • 将 SAP 日期从 20130901 转换为 01.09.2013

       将 sy-datum 写入 get_date dd/mm/yyyy。
      
    • 将 SAP 日期从 20130901 转换为 01.09.13

       将 sy-datum 写入 get_date dd/mm/yy。
      
    • 使用数据操作技术

      数据:get_date(8)。 “存储输出日期的字段
      
    • 将 SAP 日期从 20130901 转换为 01092013

       get_date(2) = sy-datum+6(2)。
           get_date+2(2) = sy-datum+4(2)。
           get_date+4(4) = sy-datum(4)。
      
    • 使用功能模块

       数据:get_date(8)。 “存储输出日期的字段
      
    • 将日期从 20130901 转换为 01SEP2013

       get_date = sy-datum.
      

      调用函数“CONVERSION_EXIT_IDATE_OUTPUT”

      <前><代码> 正在导出

      输入=获取日期

      输入

      输出 = 获取日期。

      这些所有格式均可用于特定日期/月份和年份

* to get full name of the day / month also can use


          GET_MONTH_NAME ... for month and 
            GET_DATE_DAYNAME for the specific day name too

and other methods to get other format of the date are

  • Using the WRITE statement

            data: get_date(10).  "field to store output date
    
    • Converts SAP date from 20130901 to 01.09.2013

          write sy-datum to get_date dd/mm/yyyy.
      
    • Converts SAP date from 20130901 to 01.09.13

          write sy-datum to get_date dd/mm/yy.
      
    • Using data manipulation techniques

      data: get_date(8).  "field to store output date
      
    • Converts SAP date from 20130901 to 01092013

           get_date(2)   = sy-datum+6(2).
           get_date+2(2) = sy-datum+4(2).
           get_date+4(4) = sy-datum(4).
      
    • Using Function modules

          data: get_date(8).  "field to store output date
      
    • Converts date from 20130901 to 01SEP2013

          get_date   = sy-datum.
      

      CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'

             EXPORTING
      
        input         = get_date
      
              IMPORTING
      
           OUTPUT        = get_date.
      

      these all the formats you can use for the specific dates/months and year

不忘初心 2024-08-15 10:52:39

通常,您还可以将日期导出为工厂级国家/地区特定日期格式:

if w_country is initial.
  select single LAND1
    from T001W
    into w_country
   where WERKS eq w_the_plant.
endif.

SET COUNTRY w_country.

write w_the_date to w_export.

Normally you can also export the date into the plant level country specific date format:

if w_country is initial.
  select single LAND1
    from T001W
    into w_country
   where WERKS eq w_the_plant.
endif.

SET COUNTRY w_country.

write w_the_date to w_export.
許願樹丅啲祈禱 2024-08-15 10:52:39

您可以使用简单的 FM“MONTH_NAMES_GET”

CALL FUNCTION 'MONTH_NAMES_GET'
  EXPORTING
    LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
  TABLES
    month_names = it_t247
  EXCEPTIONS
    MONTH_NAMES_NOT_FOUND = 1
    OTHERS = 2
.

IF sy-subrc 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

You may use a simple FM 'MONTH_NAMES_GET'

CALL FUNCTION 'MONTH_NAMES_GET'
  EXPORTING
    LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
  TABLES
    month_names = it_t247
  EXCEPTIONS
    MONTH_NAMES_NOT_FOUND = 1
    OTHERS = 2
.

IF sy-subrc 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
梦在深巷 2024-08-15 10:52:39
PARAMETERS: P_1 TYPE SY-DATUM.

DATA : LV_DATE TYPE SY-DATUM,LV_TIME TYPE SY-UZEIT,lv_month type string.
        LV_TIME = SY-UZEIT.

DATA: YEAR(4)   TYPE C,
      MONTH(2)  TYPE C,
      DAY(2)    TYPE C.
      YEAR = P_1+0(4).
      MONTH = P_1+4(2).
      DAY = P_1+6(2).
      IF MONTH = '01'.
      lv_month = 'JAN'.


     ELSEIF Month = '02'.
     lv_month = 'Feb'.
     ELSEIF Month = '03'.
     lv_month = 'Mar'.
     ELSEIF Month = '04'.
     lv_month = 'Apr'.
     ELSEIF Month = '05'.
     lv_month = 'May'.
     ELSEIF Month = '06'.
     lv_month = 'Jun'.
     ELSEIF Month = '07'.
     lv_month = 'Jul'.
     ELSEIF Month = '08'.
     lv_month = 'Aug'.
     ELSEIF Month = '09'.
     lv_month = 'Sep'.
     ELSEIF Month = '10'.
     lv_month = 'Oct'.
     ELSEIF Month = '11'.
     lv_month = 'Nov'.
     ELSEIF Month = '12'.
     lv_month = 'Dec'.
     ENDIF.
   WRITE: '|',day NO-GAP,'-',
  lv_month NO-GAP,'-',year NO-GAP.
PARAMETERS: P_1 TYPE SY-DATUM.

DATA : LV_DATE TYPE SY-DATUM,LV_TIME TYPE SY-UZEIT,lv_month type string.
        LV_TIME = SY-UZEIT.

DATA: YEAR(4)   TYPE C,
      MONTH(2)  TYPE C,
      DAY(2)    TYPE C.
      YEAR = P_1+0(4).
      MONTH = P_1+4(2).
      DAY = P_1+6(2).
      IF MONTH = '01'.
      lv_month = 'JAN'.


     ELSEIF Month = '02'.
     lv_month = 'Feb'.
     ELSEIF Month = '03'.
     lv_month = 'Mar'.
     ELSEIF Month = '04'.
     lv_month = 'Apr'.
     ELSEIF Month = '05'.
     lv_month = 'May'.
     ELSEIF Month = '06'.
     lv_month = 'Jun'.
     ELSEIF Month = '07'.
     lv_month = 'Jul'.
     ELSEIF Month = '08'.
     lv_month = 'Aug'.
     ELSEIF Month = '09'.
     lv_month = 'Sep'.
     ELSEIF Month = '10'.
     lv_month = 'Oct'.
     ELSEIF Month = '11'.
     lv_month = 'Nov'.
     ELSEIF Month = '12'.
     lv_month = 'Dec'.
     ENDIF.
   WRITE: '|',day NO-GAP,'-',
  lv_month NO-GAP,'-',year NO-GAP.
紫竹語嫣☆ 2024-08-15 10:52:39
data : lv_timestamp TYPE string,
         lv_str TYPE STRING.
  concatenate sy-datum sy-uzeit  into lv_timestamp.
concatenate 'C:\Users\Roopa Rani\desktop\header' '_'  lv_timestamp '.txt' INTO FILEPATH.

我觉得很有用。

data : lv_timestamp TYPE string,
         lv_str TYPE STRING.
  concatenate sy-datum sy-uzeit  into lv_timestamp.
concatenate 'C:\Users\Roopa Rani\desktop\header' '_'  lv_timestamp '.txt' INTO FILEPATH.

I think it's useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文