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 formats-time difference

Former Member
0 Likes
1,620

Hi,

Any function module which can give the date and time difference if i input the date and time in the following format

20090322 (date)

20090321 (date)

040004 (time)

040000 (time)

I had checked the other FM's but those are not in synch with the date format I am giving.Do anyone here know about a FM which can give the time difference even if we input the date and time in the above format.

Format is the problem I am facing.

Thanks,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,316

Hi:

Try function module L_MC_TIME_DIFFERENCE

Regards

Shashi

11 REPLIES 11
Read only

Former Member
0 Likes
1,316

Hi,,

SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates.

Thanks & Regards

Ashu SIngh

Read only

Former Member
0 Likes
1,317

Hi:

Try function module L_MC_TIME_DIFFERENCE

Regards

Shashi

Read only

Former Member
0 Likes
1,316

Hi,

Try this...


1. FM for difference betwwen two times:SCOV_TIME_DIFF

Import parameters               Value
 
 IM_DATE1                        2008-01-01
 IM_DATE2                        2008-01-01
 IM_TIME1                        10:00:00
 IM_TIME2                        11:30:00
 
 Export parameters               Value
 
 EX_DAYS                         0
 EX_TIME                         01:30:00

2. SD_CALC_DURATION_FROM_DATETIME : Finds the difference between two date/time and report the difference in hours
L_MC_TIME_DIFFERENCE : Finds the time difference between two date/time

Before posting the thread search in this forum you will get plenty of results

Read only

Former Member
0 Likes
1,316

Hi,

Use this function module : SD_DATETIME_DIFFERENCE

Guru

Read only

Former Member
0 Likes
1,316

HI,

Check this Code.. As most of the SAP standard FM does not outputs the Second instead it increases the by 1 Min. Check this if you want to have sec also.

DATA: l_timestamp1 TYPE ccupeaka-timestamp,
        l_timestamp2 TYPE ccupeaka-timestamp,
        l_difference TYPE i,
        l_duration   TYPE swl_pm_cvh-duration.

  CONCATENATE p_date1 p_in_time INTO l_timestamp1.
  CONCATENATE p_date2 p_out_time INTO l_timestamp2.

* Calculate time difference between timestamps in seconds
  CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'
    EXPORTING
      timestamp1 = l_timestamp2
      timestamp2 = l_timestamp1
    IMPORTING
      difference = l_difference.

* Convert time difference in seconds to HH:MM:SS format (char)
  CALL FUNCTION 'MONI_TIME_CONVERT'
    EXPORTING
      ld_duration        = l_difference
    IMPORTING
      lt_output_duration = l_duration.

* Convert HH:MM:SS(char) format into TIMS
  CONDENSE l_duration.
  CONCATENATE l_duration(2) l_duration+3(2)
              l_duration+6(2) INTO p_time_diff.

Read only

Former Member
0 Likes
1,316

Hi,

Simply subtract the two values will result in the difference in the dates in days.

Pooja

Read only

Former Member
0 Likes
1,316

Hi, friend ....try this function module as follows...

DATA: dd type p,

tt TYPE p.

CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'

EXPORTING

DATE1 = '20090322'

TIME1 = '060004'

DATE2 = '20090321'

TIME2 = '040000'

IMPORTING

DATEDIFF = dd

TIMEDIFF = tt

  • EARLIEST =

  • EXCEPTIONS

  • INVALID_DATETIME = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE: /10 dd , tt.

Read only

Former Member
0 Likes
1,316

HI USE THE FUNCTION MODULE :

SD_DATETIME_DIFFERENCE

EXACTLY MATCH FOR UR REQUIRMENT

Read only

Former Member
0 Likes
1,316

try this fm.

SD_DATETIME_DIFFERENCE

Hope it helps.

Regards

Read only

Former Member
0 Likes
1,316

HI,

DO ONE THING .

CONVERT UR DATE INTO THE FORMAT DDMMYYYY USING CODE LIKE

data : DATE1(8) LIKE SY-DATUM.

data : Lv_dd(2) type c,

Lv_mm(2) type c,

Lv_yy(4) type c.

Lv_dd = S_DATE+6(2).

Lv_mm = S_DATE+4(2).

Lv_yy = S_DATE(4).

CONCATENATE Lv_dd '.' Lv_mm '.' Lv_yy INTO DATE1.

AND THEN USE THIS DATE1 IN FUNCTION MODULE 'SD_DATETIME_DIFFERENCE'.

IT WILL DEFINATLY HELP U.

Read only

Former Member
0 Likes
1,316

Hi Folks,

I just want to avoid all the below computations and expecting to get the result irrespective of whichever the date format is,ie a function module which gives me the time difference irrespective of the date format that is fed as input.Seems it is not possible.



data:date1(08) type C value '20090322',
     date2(08) type c value '20090322',
     time1(08) type c value '060648',
     time2(08) type c value '062403',
     date3(08) type C,
     date4(08) type c,
     time3(08) type c,
     time4(08) type c,
     temp1(08) type C,
     temp2(08) type c,
     temp3(08) type c,
     temp4(08) type c,
     temp5(08) type C,
     temp6(08) type c,
     temp7(08) type c,
     temp8(08) type c,
     temp9(08) type c,
     temp10(08) type c,
     temp11(08) type c,
     temp12(08) type c,
     gpdt type d,
     gptm type t,
     smsdt type d,
     smstm type t,
     e_tdiff type cva_time,
     v_diff type cva_time,
     e_days type i.

temp1 = date1+0(4). "year
temp2 = date1+4(2)."month
temp3 = date1+6(2). "date

temp4 = time1+0(2)."hrs
temp5 = time1+2(2)."mins
temp6 = time1+4(2)."secs

temp7 = date2+0(4). "year
temp8 = date2+4(2)."month
temp9 = date2+6(2). "date

temp10 = time2+0(2)."hrs
temp11 = time2+2(2)."mins
temp12 = time2+4(2)."secs



concatenate: temp3  temp2  temp1 into gpdt,
              temp9  temp8  temp7 into smsdt,
              temp4  temp5  temp6 into gptm,
              temp10  temp11  temp12 into smstm.


CALL FUNCTION 'SCOV_TIME_DIFF'
  EXPORTING
    im_date1                    = gpdt
    im_date2                    = smsdt
    im_time1                    = gptm
    im_time2                    = smstm
 IMPORTING
   EX_DAYS                     = e_days
   EX_TIME                     = e_tdiff
* EXCEPTIONS
*   START_LARGER_THAN_END       = 1
*   OTHERS                      = 2
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
.

write:/ e_tdiff,
        e_days.

Thanks,