天天看点

abap获取日期_SAP(ABAP) 常用操作日期类函数

DATE_GET_WEEK Returns week for a date 返回日期的星期

WEEK_GET_FIRST_DAY Return first day for a week 返回星期的第一日

DATE_CONV_EXT_TO_INT Conversion of dates to SAP internal format e.g.

'28.03.2000' -> 20000328

Can also be used to check if a date is valid (

sy-subrc <> 0 )

FIRST_DAY_IN_PERIOD_GET Get first day of a period 得到第一天

LAST_DAY_IN_PERIOD_GET Get last day of a period 得到最后一天

RP_CALC_DATE_IN_INTERVAL Add days/months to a date

RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date

从日期加减一段时间得到的天数(月数)

RP_LAST_DAY_OF_MONTHS Determine last day of month 某年某个月份最后一天的的函数

SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2

dates

MONTH_NAMES_GET It returns all the month and names in repective

language.

HOLIDAY_GET Provides a table of all the holidays based upon a Factory Calendar &/ Holiday Calendar.

DATUMSAUFBEREITUNG Format date as the user settings

BKK_ADD_MONTH_TO_DATE 知道某个月某一天后,如何知道上个月该天日期

函数 BKK_GET_DAY_OF_WEEK

是输入数字显示成周几的

LAST_DAY_OF_MONTHS 一个月的最后一天

某月的最后一天

CALL FUNCTION

LAST_DAY_OF_MONTHS'

EXPORTING

day_in = zdateC

IMPORTING

last_day_of_month = zdate1.

力气用不完 10:06:01

==

力气用不完 10:08:40

RP_LAST_DAY_OF_MONTHS

******

RE_ADD_MONTH_TO_DATE 某个日期再过n个月后是哪天:

Import

Parameters 值

MONTHS 3

OLDDATE 2009.08.31

输出参数 值

NEWDATE 2009.11.30

********

获取一个日期是一年中的第几个星期

CALL FUNCTION 'DATE_GET_WEEK'

EXPORTING

date = ex_monday

IMPORTING

week = ex_week

EXCEPTIONS

date_invalid = 1

OTHERS = 2.

*获取日期所在月份的最后一天

CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = s_erdat-low

IMPORTING

last_day_of_month = s_erdat-high

EXCEPTIONS

day_in_no_date = 1

OTHERS = 2.

说明:将月份向前或向后操作,如日期20060521可以将月向前增一,变成20060621

CALL FUNCTION 'HR_BR_ADD_MONTH_TO_DATE'

EXPORTING

dmm_datin = yesterday "输入的日期

dmm_count = '2' "需要向前增加/向后减的月数

dmm_oper = '-' "给定操作符,+ 为向前增,- 为向后减

dmm_pos = 'BEG' "Set date in the beginning or end of

month,可以取space,BEG,END

IMPORTING

dmm_daout = bedat_n "输出的日期

EXCEPTIONS

unknown = 1

OTHERS = 2.

***获得月份的名称

DATA: it_month_name TYPE TABLE OF t247 WITH HEADER LINE.

CALL FUNCTION ’MONTH_NAMES_GET’ EXPORTING LANGUAGE = SY-LANGU

* IMPORTING

* RETURN_CODE = TABLES MONTH_NAMES = it_month_name

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.

*Get the monday of the current week

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

week = im_week

IMPORTING

date = ex_monday

EXCEPTIONS

week_invalid = 1

OTHERS = 2.

获得指定星期的前一个星期:

CALL FUNCTION 'LAST_WEEK'

EXPORTING

current_week = '200705' “类型SCAL-WEEK

IMPORTING

LAST_WEEK = l_week “上一个星期200704

MONDAY = d “上一星期一的日期 SY-DATUM

SUNDAY = “上一星期天的日期

日期函数:

CONVERSION_EXIT_TSTLC_OUTPUT 将YYYYMMDDhhmmss转成YYYY-MM-DD

hh:mm:ss

CONVERSION_EXIT_TSTPS_OUTPUT 将YYYYMMDDhhmmss转成YYYY-MM-DD

hh:mm:ss

CONVERSION_EXIT_ESDAT_OUTPUT 根据用户数据在年月中加分隔符,输入日期只得到年月

CONVERSION_EXIT_PERKZ_OUTPUT 根据期间标识取期间类型

CONVERSION_EXIT_INVDT_OUTPUT 逆算日期(80079398->1992-06-01)