Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date conversion

Former Member
0 Likes
1,468

Hi,

I have the date 20050703 , in the format YYYYMMDD,

and I need the most efficient way of converting it into the format DD.MM.YYYY , so the above date would be

03.07.2005

What is the best way of doing this?

thanks!!

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,387

Here is a quick way.



report zrich_0002 .


data: datum(10) type c.


concatenate sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum+0(4)
                into datum.

write:/ datum.

Regards,

Rich Heilman

12 REPLIES 12
Read only

Former Member
0 Likes
1,387

Where do you want to do it?

If in an abap list:

WRITE SY-DATUM DD/MM/YYYY.

Read only

0 Likes
1,387

Hi,

I want to put it into a variable: as in the code below

bdcdtab-dynpro = '0000'.

bdcdtab-dynbegin = ' '.

bdcdtab-fnam = 'BKPF-BUDAT'.

bdcdtab-fval = '12.07.2005'. " ybsid-budat CPosting Date in the

and I have the date in ybsid-budat

Read only

0 Likes
1,387

I think the better and easier way is to write data in format DDMMYY, and so:

WRITE MY_DATE DDMMYY TO bdcdtab-fval.

This format is ok for B.I.

Read only

0 Likes
1,387

Max,

Shouldn't this be just -

write my_date (or ybsid-budat) to bdcdtab-fval.

Sims,

This is the correct way to format date, this will format date according to the user's date format(as per user profile). You shouldn't hardcode the date format, when you can easily write more generic logic.

Cheers,

Sanjeev

Read only

0 Likes
1,387

I didn't write

write my_date (or ybsid-budat) to bdcdtab-fval.

but

write my_date (or ybsid-budat) DDMMYY to bdcdtab-fval.

So if my_date is 20050830, bdcdtab-fval is 300805.

This format is always ok for whichever B.I. of FI, infact, for example, if you use B.I. standard (RFBIBL00) all date fields are long 8 char, so you can't write date in the format that Sims want to use (30.08.2005).

Moreover this format is not depend on user's date format, so I can always be sure that my B.I. is ok for all users.

I'm agree with you, the statament WRITE has many options to format a date and it's better to use them than to process it by concatenate

Message was edited by: max bianchi

Read only

0 Likes
1,387

Please close the post once resolved so that others wont try to answer it anymore.

Thanks,

Srinivas

Read only

0 Likes
1,387

Hi,

Date formatting   

The following code demonstrates a number
 of ways to format a date value:
 
* Using the WRITE statement
***************************
  data: gd_date(10).  
      "field to store output date

* Converts date from 20020901 to 01.09.2002
  write sy-datum to gd_date dd/mm/yyyy.
* Converts 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 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.

Refer this link

http://www.sapdevelopment.co.uk/tips/date/date_format.htm

Kindly reward points and close the thread.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,388

Here is a quick way.



report zrich_0002 .


data: datum(10) type c.


concatenate sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum+0(4)
                into datum.

write:/ datum.

Regards,

Rich Heilman

Read only

0 Likes
1,387

Thanks Rich - thats done it!!

Read only

0 Likes
1,387

Please make sure to award points for helpful answers. Thanks.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,387

WRITE ybsid-budat USING EDIT MASK '__.__.____' to bdctab-fval.

Read only

Former Member
0 Likes
1,387

Hi Sims,

If you don't close the thread, people are still thinking that it is not solved for you and trying to help you. Since you mentioned, Rich's solution solved your problem, please close the thread so that others wont try to answer this.

Thanks,

Srinivas