Application Development 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: 

Comparing dates

Former Member
0 Kudos

Hi ,

In My program i need to compare date and time value

with current date and time , If DATE & TIME is in the

future, I need to set the DATE & TIME to NOW.

Please help me if you know any FM or sample code

To compare the dates and time.

Thanks in advance,

RK.

12 REPLIES 12

Former Member
0 Kudos

Hi,

You can use the below :


data : date like sy-datum value '20071231'.
data : time like sy-uzeit value '121212'.
at selection-screen.

if date GT sy-datum.
date = sy-datum.
endif.

if time GT sy-uzeit.
time = sy-uzeit.
endif.

.

Thanks,

Sriram Ponna.

0 Kudos

Hi sriram,

Thanks for response,

I want to compare date and time at a time, Not individually.

Please help.

Thanks,

RK.

Hi Ravi,

Please check the FM SD_DATETIME_DIFFERENCE.

In the result if you get difference is 1.

Then you can reset the date and time to current.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi,

You can do like this

Loop at itab into wa.

if wa-date NE sy-datum and wa-time NE sy-uzeit.

wa-date = sy-datum.

wa-time = sy-uzeit.

modify itab from wa transporting date time.

clear wa.

endif.

endloop.

Regards,

Satish

former_member156446
Active Contributor
0 Kudos

DATE_COMPUTE_DAY

DATE_GET_WEEK

hi put in a condition saying

if sy-datum > ur date

ur date = sy-datum.

endif.

if sy-uzeit > ur time

ur time = sy-uzeit.

endif.

Former Member
0 Kudos

hi,

a) Check this FM 'HR_HK_DIFF_BT_2_DATES'.

b) think this two function modules can help u out..just let me know were this useful..

SD_DATETIME_DIFFERENCE

Give the difference in Days and Time for 2 dates

FIMA_DAYS_AND_MONTHS_AND_YEARS

Get number of days. Year, Months between two dates.

by using either of one u can get the difference, if difference is -ve , set date and time to system date and time

regards,

pavan

Former Member
0 Kudos

Hi Ravi,

Try any one of this function modules in these you compare sy-datum and sy-uzeit..

HRVE_GET_TIME_BETWEEN_DATES

CX_SCHED_VIA_OPERATING_TIME

SD_DATETIME_DIFFERENCE

SD_CALC_DURATION_FROM_DATETIME

Plz Reward if useful.

Mahi.

Former Member
0 Kudos

Hi

Ravi

as they said you can use FM

or if u want logic dont compare date and time explicitly

do like this

data:

w_d1 int i,

w_t1 type i,

w_d2 type i,

w_t2 type i,

w_d1 = sy-datum.

w_t1 = sy-uzeit.

w_d2 = ur_date.

w_t2 = ur_time.

if (w_d1 + w_t1 ) le ( w_d2 + w_t2 ) .

ur_date = sy-datum.

ur_time = sy-uzeit.

endif.

plzzz reward if useful dont forget to reward plzz

Former Member
0 Kudos

Hi

Ravi

as they said you can use FM

or if u want logic dont compare date and time explicitly

do like this

data:

w_d1 int i,

w_t1 type i,

w_d2 type i,

w_t2 type i,

w_d1 = sy-datum.

w_t1 = sy-uzeit.

w_d2 = ur_date.

w_t2 = ur_time.

if (w_d1 + w_t1 ) le ( w_d2 + w_t2 ) .

ur_date = sy-datum.

ur_time = sy-uzeit.

endif.

plzzz reward if useful dont forget to reward plzz

0 Kudos

Hi sunil kumar,

Thanks for response.

I didnt uinderstand you below logic, How to compare this.

if ( w_d1 + w_t1 ) le ( w_d2 + w_t2 ) .

endif.

Thanks,

RK

0 Kudos

Hi ravi,

1. this is a TRICKY logic

2. suppose the date and time variables are d and t.

and current date and time is sy-datum, sy-uzeit.

3.

*------ compare if date and time are greater than NOW

if (d > sy-datum) or

(d = sy-datum and t > sy-uzeit).

d = sy-datum

t = sy-uzeit.

endif.

regards,

amit m.

0 Kudos

Hello Amit,

I had a similar issue ( a bit more complex though ), your reply has helped me fix it. Thanks.

Regarda,

Mohammed Muzammil.