[英]How do I get day number from a date in abap?
I need to convert a date in 'MM/DD/YYYY' format to a number that say which day in the year it is.我需要将 'MM/DD/YYYY' 格式的日期转换为一个数字,说明它是一年中的哪一天。 IE '01/01/YYYY'=1 and '12/31/YYYY'=365.
即 '01/01/YYYY'=1 和 '12/31/YYYY'=365。 Is there any built in function to do this in ABAP?
是否有任何内置函数可以在 ABAP 中执行此操作? I've tried googling but I couldn't find any functions which did this
我试过谷歌搜索,但我找不到任何这样做的功能
It is absolutely unnecessary to rely on any function module that may or may not be present in your system.绝对没有必要依赖系统中可能存在或不存在的任何功能模块。 Just use basic built-in language elements:
只需使用基本的内置语言元素:
DATA: l_my_date TYPE d, " note that the data type D is YYYYMMDD
l_jan_01 TYPE d, " This will be jan 1 of the needed year
l_day TYPE i.
l_my_date = ...whatever...
l_jan_01 = l_my_date.
l_jan_01+4 = '0101'. " or any other means to get the first day of the year.
l_day = l_my_date - l_jan_01 + 1.
给你一行代码:
DATA(g_day) = p_date - CONV d( p_date(4) && '0101' ) + 1.
You can use this function module: HR_AUPBS_MONTH_DAY
.您可以使用这个功能模块:
HR_AUPBS_MONTH_DAY
。
You have to pass an initial date and an end date, and it will return the number of days in between (this is what you want):你必须传递一个初始日期和一个结束日期,它会返回之间的天数(这是你想要的):
CALL FUNCTION 'HR_AUPBS_MONTH_DAY'
EXPORTING BEG_DA = P_BEGDA " Here you should put the first day of the year
END_DA = P_ENDDA " Here you put the date
IMPORTING NO_CAL_DAY = P_CAL_DAY. " This is what you want
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.