Skip to Content
author's profile photo Former Member
Former Member

How to convert "any" date format to internal format

Hi,

I want to convert any date format to internal format. Is there any function module ?

The date formats could be:

DD.MM.YYYY

MM/DD/YYYY

MM-DD-YYYY

YYYY.MM.DD

YYYY/MM/DD

YYYY-MM-DD

Thank you,

Surya

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 03:51 PM

    Hi,

    Check this link for a sample FM code for converting any external format to internal format..

    https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-FunctionmoduleforconvertinganyExternaldateformattoInternalformat

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 25, 2007 at 02:03 PM

    You can use the function call CONVERT_DATE_TO_INTERNAL.

    ~Suresh

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 25, 2007 at 02:04 PM

    Check -

    CONVERT_DATE_TO_INTERNAL

    Regards,

    Amit

    Reward all helpful replies.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 02:05 PM

    Hi,

    Create a variable like sy-datum and assing the date to it.

    This is like,

    DATA: l_date like sy-datum.
    
    l_date = 'Date'.   "<-- Assign any date format here.

    Sy-datum always store date in internal format.

    Regards,

    RS

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 02:07 PM

    You can use Function Module :

    DATE_STRING_FORMAT

    Regard,

    Rohit

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 25, 2007 at 02:08 PM

    Hi,

    Please check this FM.

    CONVERSION_EXIT_SDATE_INPUT

    CONVERT_DATE_TO_INTERN_FORMAT

    Regards,

    Ferry Lianto

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi All,

      Thank you for the quick response.

      I used FMs CONVERT_DATE_TO_INTERN_FORMAT and CONVERT_DATE_TO_INTERNAL both working withe date format mm/dd/yyyy, which is my user default date format. For remaining date formats, these FMs are not working.

      Thank you,

      Surya

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 03:20 PM

    Hi Surya,

    if these are the Only formats you can do this..

    <b>data:</b>

    w_output(8) type c.

    w_date(10) = p_date.

    <b>Case w_date+2(1).</b>

    when '.'.

    concatenate w_date6(4) w_date3(2) w_date+0(2) into w_output.

    when '/' or '-'.

    concatenate w_date6(4) w_date0(2) w_date+3(2) into w_output.

    when others.

    concatenate w_date0(4) w_date4(2) w_date+6(2) into w_output.

    endcase.

    <b>

    write: w_output.</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 03:31 PM

    Hi,

    Check this sample program..It will convert sap supported external format to the internal format..

    PARAMETERS: v_char(10).

    DATA: v_date TYPE sydatum.

    DATA: v_period TYPE usr01-datfm.

    • Get the format.

    • DD.MM.YYYY

    IF v_char+2(1) = '.'.

    CONCATENATE v_char6(4) v_char3(2) v_char(2) INTO v_date.

    ENDIF.

    • MM/DD/YYYY

    IF v_char+2(1) = '/'.

    CONCATENATE v_char6(4) v_char(2) v_char3(2) INTO v_date.

    ENDIF.

    • MM-DD-YYYY

    IF v_char+2(1) = '-'.

    CONCATENATE v_char6(4) v_char(2) v_char3(2) INTO v_date.

    ENDIF.

    • YYYY.MM.DD

    IF v_char+4(1) = '.'.

    CONCATENATE v_char(4) v_char5(2) v_char8(2) INTO v_date.

    ENDIF.

    • YYYY/MM/DD

    IF v_char+4(1) = '/'.

    CONCATENATE v_char(4) v_char5(2) v_char8(2) INTO v_date.

    ENDIF.

    • YYYY-MM-DD

    IF v_char+4(1) = '-'.

    CONCATENATE v_char(4) v_char5(2) v_char8(2) INTO v_date.

    ENDIF.

    WRITE: / v_date.

    Thanks,

    Naren

    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.