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

Subtract hours from current time

Former Member
0 Likes
12,829

Hello experts ,

I want to know how i can subtract hours from current time ( sy-uzeit )

What is the name of function that implement this task ?

For example : if current time is 1:30:00 ,

And i want subtract 3 hours , the result will be 22:30:00.

Thanks for the help .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
6,475

Hello,

This is a small ABAP program that will help you.

The subtraction is always calculated in seconds.


report ztest.
* This report will subtract 3 hours from the current time.

data: w_time like sy-uzeit.
data: w_seconds type i.

w_seconds = 3 * 3600.

w_time = sy-uzeit - w_seconds.
write: / w_time.

Wim

9 REPLIES 9
Read only

Former Member
0 Likes
6,475
Read only

0 Likes
6,475

Hello ,

Thanks for the help but this link was not give me answer on my question.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
6,475

Hello Avi,

Please check "TIMECALC_MOVE" FM. Here you have to pass '-' to the IMPORT param DIRECTION.

As you are subtracting the time.

BR,

Suhas

Read only

satsrockford
Active Participant
0 Likes
6,475

hi

declare a local variable W_UZEIT type SY_UZEIT.

and write the code

w_uzeit = sy-uzeit - 10800.

When we subtract 3hrs from SY_UZEIT it will subtract 10800 seconds from the system time (SY_UZEIT gives system time ).This is equivalent to subtracting 3 hrs.

Here we are not modifying SY-UZEIT... instead we are declaring a variable W_UZEIT and assigning the subtracted value.

regards

Satish

Read only

Former Member
0 Likes
6,475

Hi,

Try Using the FM SD_CALC_DURATION_FROM_DATETIME

Hope it helps u out.

Thanks & Regards

Read only

0 Likes
6,475

Hello,

This FM give difference ( in hour ) between 2 elements of date and time.

This FM was not help me , thanks.

Read only

0 Likes
6,475

Hello,

Did you check the little ABAP program I posted, it will always work.

Wim

Read only

Former Member
0 Likes
6,475

Hi

Refer This Link

Ranga

Read only

Former Member
0 Likes
6,476

Hello,

This is a small ABAP program that will help you.

The subtraction is always calculated in seconds.


report ztest.
* This report will subtract 3 hours from the current time.

data: w_time like sy-uzeit.
data: w_seconds type i.

w_seconds = 3 * 3600.

w_time = sy-uzeit - w_seconds.
write: / w_time.

Wim