Application Development 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: 

problem with date convertion

Former Member
0 Kudos

Hi friends,

I tried to use a simple format convertion, and i have problem, take a look of this code:

data: date_mask TYPE c LENGTH 8.

write sy-datum to date_mask DD/MM/YY.

write date_mask DD/MM/YY.

Output:

18.12.06

I debugg time:

sy-datum: 20061218

date_mask: 18.12.06

And i expect that the output were: "18/12/06".

Thanks,

Albio.-

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Interesting. The DD/MM/YY or DD/MM/YYY changes the length of the output, but the actual separator is from the user master record

SAP F1 help: <b>For the character /, the separator that is defined in the user master record for date output is inserted</b>.

Another option would be to create your own conversion exit, but this is probably over-kill.

8 REPLIES 8

Former Member
0 Kudos

hi,

Use can use this code, it will print date according to required format:

data: date_mask TYPE c LENGTH 8.

data: v1(2) type c,

v2(2) type c,

v3(2) type c.

constants: slash type c value '/'.

start-of-selection.

v1 = sy-datum+6(2).

v2 = sy-datum+4(2).

v3 = sy-datum+2(2).

concatenate v1 slash v2 slash v3 into date_mask .

0 Kudos

Hi Ashvender Singh,

Thanks for your reponse, i think your code it's going to work fine, but my question it's focused in order to know why the format option for the write statement doesn't work how it should do it.

I mean if i use "write sy-datum to var dd/mm/yy" the output should be in format "dd/mm/yy" and not "dd.mm.yy", that's the point.

Insted of that, thanks for your idea.

Albio.-

0 Kudos

Hi,

The format is not working because of country settings.

The date setting is defined with dots (.). so you need to set the country first.

Just try using set country statement before the assigning the sy-datum to variable. It will convert according to the country date settings.

set country 'US'.

0 Kudos

is it helpful answer?

Former Member
0 Kudos

Hi,

Is the problem solved?

Ashven

Former Member
0 Kudos

Interesting. The DD/MM/YY or DD/MM/YYY changes the length of the output, but the actual separator is from the user master record

SAP F1 help: <b>For the character /, the separator that is defined in the user master record for date output is inserted</b>.

Another option would be to create your own conversion exit, but this is probably over-kill.

0 Kudos

Hi.

Well, thanks all for your help.

I Tried with set country 'US', but this country uses the format MM/DD/YY, and i need DD/MM/YY.

Finally i used this intruction:

REPLACE ALL OCCURRENCES OF '.' IN date_var WITH '/'.

And this resolve it.

Thanks,

Albio.-

0 Kudos

Hi,

If your problem is solved assign points.

Ashven