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

convert the date

Former Member
0 Likes
743

Hi Experts,

Is there any FM to Convert the date from 04/01/2009 to 4/1/2009?

i want to remove the zero before the date and month.

Regards.

1 ACCEPTED SOLUTION
Read only

faisalatsap
Active Contributor
0 Likes
675

Hi,

Test the following Sample Code it will solve out your problem,

PARAMETERS: date like sy-datum.
data: day(2),
      month(2),
      year(4),
      cdate(10).

day = date+6(2).
month = date+4(2).
year = date+0(4).

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input         = day
 IMPORTING
   OUTPUT        = day
          .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input         = month
 IMPORTING
   OUTPUT        = month
          .
CONCATENATE: day '/' month '/' year into cdate.

WRITE: cdate.

Best Regards,

Faisal

5 REPLIES 5
Read only

faisalatsap
Active Contributor
0 Likes
676

Hi,

Test the following Sample Code it will solve out your problem,

PARAMETERS: date like sy-datum.
data: day(2),
      month(2),
      year(4),
      cdate(10).

day = date+6(2).
month = date+4(2).
year = date+0(4).

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input         = day
 IMPORTING
   OUTPUT        = day
          .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input         = month
 IMPORTING
   OUTPUT        = month
          .
CONCATENATE: day '/' month '/' year into cdate.

WRITE: cdate.

Best Regards,

Faisal

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
675

HI,

DATA : wa_date(10) VALUE '04/01/2009',
       wa_mnt(2),
       wa_dt(2),
       wa_year(4).

SPLIT wa_date AT '/' INTO wa_mnt
                          wa_dt
                          wa_year.

CONCATENATE wa_mnt+1(1) wa_dt+1(1) wa_year INTO wa_date SEPARATED BY '/'.
BREAK-POINT.

Thanks & Regards

Read only

0 Likes
675

Sorry, Always Learner

Your code can create problem for date like 24.12.2008 it will show it 4/2/2008

Best Regards,

Faisal

Read only

0 Likes
675

yes..u r right..

i gave the solution as per the thread

converting date from 04/01/2009 to 4/1/2009

To convert in above format my code works fine

Read only

Former Member
0 Likes
675

Is there any FM to Convert the date from 04/01/2009 to 4/1/2009?

i want to remove the zero before the date and month.

data:lv_date(10) type c,

lv_day(2) type c,

lv_month(2) type c,

lv_year(4) type c.

lv_date = '04/01/2009'.

lv_year = lv_date+6(4).

lv_day = lv_date+0(2).

lv_month = lv_date+3(2).

if lv_day(1) = '0'.

lv_day = lv_day+1(1).

endif.

if lv_month(1) = '0'.

lv_month = lv_month+1(1).

endif.

concatenate

lv_day

lv_month

lv_year

into lv_date

separated by '/'.

write: lv_date.