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: 

date format

Former Member
0 Kudos

hi friends,

user has to upload data to TCODE here DATE field has to

accept all formats[eg.MM/DD/YYYY,DD/MM/YYYY,YYYY/MM/DD etc.,,] so plz tell how to code this r is there any variable plz suggest me any code with eg

thanks

soorya

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

each user has a defualt date setting maintaineed in

USR01

so first make a query on the usr01 table and get the default date

then convert all the dates into the default user format.

in the sample code i'm taking simple date like 20060101

and getting year month & date

SELECT SINGLE DATFM

FROM USR01

INTO (V_DATFORMAT)

WHERE BNAME = SY-UNAME.

YEAR = DATESTRING+0(4).

MONTH = DATESTRING+4(2).

DATE = DATESTRING+6(2).

CASE V_DATFORMAT.

WHEN 1.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '.'.

WHEN 2.

CONCATENATE MONTH DATE YEAR INTO DATESTRING SEPARATED BY '/'.

WHEN 3.

CONCATENATE MONTH DATE YEAR INTO DATESTRING SEPARATED BY '-'.

WHEN 4.

CONCATENATE YEAR MONTH DATE INTO DATESTRING SEPARATED BY '.'.

WHEN 5.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '/'.

WHEN 6.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '-'.

ENDCASE.

7 REPLIES 7

Former Member
0 Kudos

hi

each user has a defualt date setting maintaineed in

USR01

so first make a query on the usr01 table and get the default date

then convert all the dates into the default user format.

in the sample code i'm taking simple date like 20060101

and getting year month & date

SELECT SINGLE DATFM

FROM USR01

INTO (V_DATFORMAT)

WHERE BNAME = SY-UNAME.

YEAR = DATESTRING+0(4).

MONTH = DATESTRING+4(2).

DATE = DATESTRING+6(2).

CASE V_DATFORMAT.

WHEN 1.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '.'.

WHEN 2.

CONCATENATE MONTH DATE YEAR INTO DATESTRING SEPARATED BY '/'.

WHEN 3.

CONCATENATE MONTH DATE YEAR INTO DATESTRING SEPARATED BY '-'.

WHEN 4.

CONCATENATE YEAR MONTH DATE INTO DATESTRING SEPARATED BY '.'.

WHEN 5.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '/'.

WHEN 6.

CONCATENATE DATE MONTH YEAR INTO DATESTRING SEPARATED BY '-'.

ENDCASE.

former_member181962
Active Contributor
0 Kudos

Get your date in internal format.

Then you can use the write statement to get the user defined format for the date.

data: v_datum type sy-datum,

v_date_new(10).

write: v_datum to v_date_new.

REgards,

Ravi

Former Member
0 Kudos

Hi,

You can make the screen accept the date format specified in the user defaults, which you can see in SU01 transaction, else you will take wahtever the user enters and change the format and put it in the field.

regards,

Ravi

former_member188685
Active Contributor
0 Kudos

Hi,

in Table <b>USR01</b> check the field <b>DATFM</b> , this will tell you in which format it can take.

Regards

vijay

rahulkavuri
Active Contributor
0 Kudos

use this FM.

CONVERT_DATE_TO_INTERN_FORMAT

pass DTYPE = 'DATS'.

this function module will take care of the user's defined settings and accordingly convert into proper format

Former Member
0 Kudos

Hi,

Use CONVERT_DATE_TO_INTERN_FORMAT

pass DTYPE = 'DATS'.

This FM will TAKE CARE OF THE USERS SETTINGSAND ACCORDINGLY CONVERT INTO PROPER FORMAT

(IE NITERNAL FORMAT OF YYYYMMDD)

Hope it helps you.

Regards,

Anjali

Former Member
0 Kudos

Hi soorya,

1. Simple.

2. Instead of worrying about the

user format,

just use

WRITE date to variable.

(and use this variable in bdc data)

<b>(WRITE will AUTOMATICALLY TAKE CARE OF USER SETTINGS)</b>

3. just copy paste to get a taste of it.

4.

report abc.

*----


data : d type sy-datum.

data : mydate(10) type c.

*----


start-of-selection.

d = '20060525'.

<b> write d to mydate.</b>

*----


write 😕 mydate..

regards,

amit m.