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

How can I convert system date into user specified format?

Former Member
0 Likes
8,181

Hi Experts...

   I have a requirement to get the current date in user specified format.

I am using function module which will return the user specific date format (DATFM) and that I am storing into a variable.

Now I need to convert current date into that particular format.

suppose gd_format will store the user spcific date format.

I used the following code to convert the system date into that format.

WRITE: sy-datum USEING EDIT MASK gd_format TO gd_date.

But it will store the format itself into gd_date insted of the date.

Eg: If gd_format is DD.MM.YYYY and sy-datum is 20120824

After using the Write statement

The value in gd_date is DD.MM.YYYY.

I want date in gd_date as per the user specified format. That can be different for different users.

Kindly help me..

Thanks

Pradeep

Hi Experts...

   I have a requirement to get the current date in user specified format.

I am using function module which will return the user specific date format (DATFM) and that I am storing into a variable.

Now I need to convert current date into that particular format.

suppose gd_format will store the user spcific date format.

I used the following code to convert the system date into that format.

WRITE: sy-datum USEING EDIT MASK gd_format TO gd_date.

But it will store the format itself into gd_date insted of the date.

Eg: If gd_format is DD.MM.YYYY and sy-datum is 20120824

After using the Write statement

The value in gd_date is DD.MM.YYYY.

I want date in gd_date as per the user specified format. That can be different for different users.

Kindly help me..

Thanks

Pradeep

11 REPLIES 11
Read only

Former Member
0 Likes
4,278

hi pradeep,

please try this,

date1 = sy-datum.

time = sy-timlo.

WRITE date1 USING EDIT MASK '____/__/__' TO lv1.

WRITE time USING EDIT MASK '__:__:__' TO lv2.

write 😕  lv1 DD/MM/YYYY.

use underscor instead of DD MM YYYY

thanks,

marimuthu.k

Read only

bharat_rathod2
Active Participant
0 Likes
4,278

Dear,

please tell me how you can identify which user want which format?

Read only

Former Member
0 Likes
4,278

Have a look at this Link.Maybe this might provide you with the solution that you want.Please give Points if link was found useful.

http://wiki.sdn.sap.com/wiki/display/Snippets/ABAP+-+Function+module+for+converting+any+External+dat...

Read only

Former Member
0 Likes
4,278

hi pradeep,

please try the following,

DATA : date1 TYPE char8,
time  TYPE char6,
var10 TYPE char10,
var8  TYPE char8,
lv_length TYPE i,
li        TYPE i,
lv_off    TYPE i,
z TYPE char2.
PARAMETER lv TYPE char10.
date1 = sy-datum.
time = sy-timlo.
FIELD-SYMBOLS <f> TYPE char10.
ASSIGN lv TO <f>.
<f> = lv.

FIND ALL OCCURRENCES OF 'DD'  IN  <f> MATCH LENGTH lv_length MATCH OFFSET lv_off.
var10+lv_off(lv_length) = date1+6(2).
li = lv_off + lv_length.
IF li <> 10.
   lv_off = li.
   var10+lv_off(1) = '/'.
ENDIF.

FIND ALL OCCURRENCES OF 'MM'  IN  <f> MATCH LENGTH lv_length MATCH OFFSET lv_off.
var10+lv_off(lv_length) = date1+4(2).
li = lv_off + lv_length.
IF li <> 10.
   lv_off = li.
   var10+lv_off(1) = '/'.
ENDIF.

FIND ALL OCCURRENCES OF 'YYYY'  IN  <f> MATCH LENGTH lv_length MATCH OFFSET lv_off.
var10+lv_off(lv_length) = date1+0(4).
li = lv_off + lv_length.
IF li <> 10.
   lv_off = li.
   var10+lv_off(1) = '/'.
ENDIF.

WRITE: date1,var10.

if u give input DD/mm/yyyy like this u ll get o/p as 25/08/2012.

in ur case instead of lv pass gd_date u will get desired o/p.

reward points if it is useful.

thanks,

marimuthu.k

Read only

former_member189905
Participant
0 Likes
4,278

Hi,

Can you try this and give me the result :

WRITE sy-datum TO gd_date USING EDIT MASK gd_format.

Khalid.

Read only

bharat_rathod2
Active Participant
0 Likes
4,278

Dear first give me answer

where you define that which user want which formt?

means user and format combination is fixed or not?

if fix then where it is?

if not then how you get the format for user?

Read only

Former Member
0 Likes
4,278

Hi,

check out the below thread

http://scn.sap.com/thread/837696

hope it helps!

Read only

Former Member
0 Likes
4,278

Hi,

You just need to call the FM CONVERT_DATE_TO_EXTERNAL, which take the user format into account...

Manu.

Read only

Former Member
0 Likes
4,278

Use FM   FORMAT_DATE_4_OUTPUT

For ex,

              CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
              EXPORTING
                datin  = sy-datum
                format = 'DD.MM.YYYY'
              IMPORTING
                datex  = result.

you can pass format in export parameter 'format'.

Regards.

Kaushik Savaliya

Read only

former_member215575
Active Participant
0 Likes
4,278

Hi Pradeep,

Use FM SLS_MISC_CONVERT_TO_DATE to convert date sy-datum format to user default format.

Hi Bharat,

User format is defaulted in (Menu option:System-->User Profile-->Own data) or can also be found in USR01 table. Check DATFM field passing BNAME. Use domain value range of DATFM to indentify what format is set for the user.

Regards,

Sravan Guduru

Read only

maxx
Explorer
4,278

data(today) = |{ sy-datum DATE = USER }|. "ABAP 7.4+