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

URGENT : Hours between two dates !!

Former Member
0 Likes
1,678

Hi everybody

we have an urgent requirement to track the effort .

We need to find the hours between two dates.

IS there any Function Module in SAP for this ??

Any pointers on the same would be useful.

Regards

Pankaj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,147

Try the FM CCU_TIMESTAMP_DIFFERENCE

It gives you the difference between two timestamps in seconds..which you can divide by 3600 to get hours.

9 REPLIES 9
Read only

Former Member
0 Likes
1,148

Try the FM CCU_TIMESTAMP_DIFFERENCE

It gives you the difference between two timestamps in seconds..which you can divide by 3600 to get hours.

Read only

0 Likes
1,147

hi anurag..

thanks for your concern.

i tried the listed FM but it gives a negative value..

any feedback is welcome.

Regards

pankaj

Read only

0 Likes
1,147

It would give you positive result if the Timestamp1 is greater than timestamp2.

Extract from the FM code.

IF TIMESTAMP1 < TIMESTAMP2.

SIGN_FACTOR = -1.

DATE2 = TIMESTAMP1(8).

TIME2 = TIMESTAMP1+8(6).

DATE1 = TIMESTAMP2(8).

TIME1 = TIMESTAMP2+8(6).

ELSE.

SIGN_FACTOR = 1.

DATE1 = TIMESTAMP1(8).

TIME1 = TIMESTAMP1+8(6).

DATE2 = TIMESTAMP2(8).

TIME2 = TIMESTAMP2+8(6).

ENDIF.

Read only

Former Member
0 Likes
1,147

hi

good

try this function module

SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates

thanks

mrutyun^

Read only

0 Likes
1,147

hi ..

the function module SD_DATETIME_DIFFERENCE is helpful

in the problem context ..but not entirely..

it gives an insight into the code structure..

thanks & Regards

pankaj

Read only

Former Member
0 Likes
1,147

Hullo,

the following functionmodule might be what you are looking for: 'L_TO_TIME_DIFF'

call function 'L_TO_TIME_DIFF'
  exporting     
    i_start_date           = i_qmel-strmn
    i_start_time           = i_qmel-strur
    i_end_date             = i_final-budat2
    i_end_time             = i_final-erzet2
    i_time_uom             = 'H'  
  importing
    e_time_diff            = ydatdiff
* EXCEPTIONS
*   INPUT_DATA_EMPTY       = 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.

Read only

0 Likes
1,147

Hi R.Ebus ...

i tried it out ..

bt it doesn't work...

thanks for your endeavor ...

Regards

Pankaj

Read only

0 Likes
1,147

You can always code it yourself:

DATA: start_date TYPE sy-datum VALUE '20061101',
      end_date   TYPE sy-datum VALUE '20061108',
      days_between type i,
      hours_between type i.

days_between = end_date - start_date.

hours_between = days_between * 24.

Maybe this will help you.

Read only

anversha_s
Active Contributor
0 Likes
1,147

Hi pankaj,

try this.

data : date1 type sy-datum,  
     date2 type sy-datum,    
   time1 type sy-uzeit,   
    time2 type sy-uzeit,   
    v_datediff type p,      
 v_timediff type p.      
 date1 = '20060101'.   
    date2 = sy-datum.    
 
 
   time1 = '010101'.     
  time2 = sy-uzeit.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'  
EXPORTING    
DATE1                  = DATE1   
TIME1                  = TIME1  
DATE2                  = DATE2   
TIME2                  = TIME2
IMPORTING  
DATEDIFF               = v_DATEDIFF   
TIMEDIFF               = v_TIMEDIFF
*EARLIEST              = 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.

<i><b>with oyut any FM</b></i>

data: t1 type tims,
t2 type tims,
t3 type tims,
time_second type i.

t1 = '193030'.
t2 = '093000'.


t3 = t1 - t2.


time_second = ( 60 * t3+0(2) ) + ( 60 * t3+2(2) ) + t3+4(2).

write :/ 't1:-', t1 ,' t2:-', t2 , ' t3:-', t3.

rgds

Anver

if hlped pls mark points

Message was edited by: Anversha s