Skip to Content

Convert date as per specified format?

Hello

Do we have any function, wherein the import params are

1) DATE_IN, (Example: MM/DD/YYYY )

2) DATE_FORMAT_IN, (Example: 2)

3) DATE_FORMAT_OUT, (Example:1 )

and the Export params are,

1) DATE_OUT (Example: DD.MM.YYYY)

2) DATE_AS_PER_INTERNAL_FORMATE (Example: YYYYMMDD)

if we don't have any straight forward single function. 2 step process also fine

I searched in SE37 by using wild cards like, *DATE*CONVERT* and *DATE*FORMAT*, but no success

Thank you

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 05:04 AM

    Hi,

    Pleas try this FM. All you need to know is the diffeent formats of date. You can program it accordingly.

    Links for different formats use the link provided by Maju.

    http://wiki.scn.sap.com/wiki/display/Snippets/FUNCTION+MODULE+FOR+CONVERTING+DATE+INTO+THE+GIVEN+FORMAT

    PARAMETERS l_dat TYPE NLEI-IBGDT.

    data l_str Type RN1DATUM-DATEX.

    call function 'FORMAT_DATE_4_OUTPUT'
    exporting
    datin = l_dat
    format = 'YYYYMMDD'
    importing
    datex = l_str.
    WRITE l_str.

    Hope this helps.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 03:29 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 27, 2013 at 03:38 AM

    Hi MSR

    You can try like this

    * Using the WRITE statement

    ***************************

    data: gd_date(10). "field to store output date

    * Converts SAP date from 20020901 to 01.09.2002

    write sy-datum to gd_date dd/mm/yyyy.

    * Converts SAP date from 20020901 to 01.09.02

    write sy-datum to gd_date dd/mm/yy.

    * Using data manipulation techniques

    ************************************

    data: gd_date(8). "field to store output date

    * Converts SAP date from 20010901 to 01092001

    gd_date(2) = sy-datum+6(2).

    gd_date+2(2) = sy-datum+4(2).

    gd_date+4(4) = sy-datum(4).

    * Using Function modules

    ************************

    data: gd_date(8). "field to store output date

    * Converts date from 20010901 to 01SEP2001

    gd_date = sy-datum.

    CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'

    EXPORTING

    input = gd_date

    IMPORTING

    OUTPUT = gd_date.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 27, 2013 at 03:47 AM

    Dear MSR,

    One small concept you need to learn. Rest of all Example you can do by yourself.

    Let my LV_date is type dats(Char8). And input is coming like yyyymmdd.

    Now make a lv_date_new type string which will keep modified date.

    lv_year type char4.

    lv_month type char2.

    lv_day type char2.

    lv_day = lv_date+6(2).

    In the statement we are fetching data from lv_date start with 6th character and next 2 character.means we will start from M to DD. so now lv_day will carry DD. so now you can fetch month lv_date+4(2) and year lv_date+0(4) with same concept.

    now concatenate your all data day month year separated by . or / or -

    BR

    ChanS

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 03:57 AM

    Hi MSR,

    We can output the date in our own requirement .Here to go,

    DATA: a(8) TYPE c, b(10) TYPE c.

    a = sy-datum or p_date.-------------- or ur input parameter (p_date)

    CONCATENATE a+6(2) '/' a+4(2) '/' a+0(4) INTO b. ----_DD/MM/YYYY

    CONCATENATE a+6(2) '.' a+4(2) '.' a+0(4) INTO b.-------------DD.MM.YYYYY

    CONCATENATE a+6(2) '-' a+4(2) '-' a+0(4) INTO b. -----------DD-MM-YYYY

    write b.

    Cheers

    regards

    Syed

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 04:30 AM

    Hi MSR,

    Please find below useful code .

    data : date_out type char10.

    write date_in to date_out.

    With Regards,

    Ram.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 04:37 AM

    Hi,

    Use the FM 'HR_IN_GET_DATE_COMPONENTS' and concatenate as per the requirement, use any separator ( . - /)

    CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'

    EXPORTING

    idate = date "use sy-datum directly here

    IMPORTING

    DAY = dd "day

    MONTH = mm " month

    YEAR = yy" year.

    CONCATENATE dd mm yy into txt SEPARATED BY '-'.

    Regards,

    Jeffin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 04:46 AM

    Hi,

    Goto a report program press on pattern button type string like given below.

    Take your desired format you need.

    Regards,

    Alenlee MJ


    Capture.PNG (47.2 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 27, 2013 at 05:13 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.