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

Comparing Dates

Former Member
0 Likes
4,551

Hi,

i have a period of dates in my internal table as start date and end date. i need to compare these dates with the period dates of the selection screen.

for example, whether these start and end dates are in between the selection screen dates(also have two dates, start and end).

Depend on that i need to calculate teh duration.To do this, do i have any Function modules or just i have to follow normal date calculations.Pls suggest me.

Thanks,

Ram.

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,608

just go for normal date calculations...

Read only

Former Member
0 Likes
1,608

Hi Ram,

You have to go for normal comparisions as we do for comparing any numerci values.

Regards,

Najmuddin.

Read only

Former Member
0 Likes
1,608

Try these FMs:

ISM_SD_DATE_BETWEEN_TO_RANGE ,FIMA_DAYS_BETWEEN_TWO_DATES,FIMA_DAYS_BETWEEN_TWO_DATES_2,LAGF_DAYS_BETWEEN_2_DATES_GET,DAYS_BETWEEN_TWO_DATES,HR_99S_INTERVAL_BETWEEN_DATES

Read only

former_member156446
Active Contributor
0 Likes
1,608

1.To get a date from a given date +/- period. Input : Date & Period (No. of Days) Output : Calculated Date

Please go through the Function Module "RELATIVE_DATE_CALCULATE". Remember to enter the date in 'yyyymmdd' format in the start date field.

2.if the days variable is integer and other 2 like sy-datum, the math below yields the number of days to yo.. start date = '23.07.2003' End date = '23.09.2003' Days = enddate - Start date.

3. Please go through the Functions Module , it gives date as well as time difference, though U may have to enter time as well. SD_DATETIME_DIFFERENCE

4. with this FM you can get dates between two dates : Function Module RP_CALC_DATE_IN_INTERVAL 5. go into SE37 and search on 'difference between dates', one of these 3 keywords or a combination between the 3 will give you a function module.

6. Date Upper & Lower limit: the lower is obviously the 1st of the month. To get the upper use function module END_OF_MONTH_DETERMINE.

7. to get the logon user setting date dynamically : Using offsets move it into a date field,obviously in the format yyyymmdd. then move it into a char(10) field. U get the data in char(10) using the current user's setting. ex:: w_date type d value '20030822', w_char(10). say logon user setting is mm/dd/yyyy. write w_date to w_char. w_char will have the value 08/22/2003.

You can use the result of the move stmt in bdc table.

8. Check this FM "/SAPDMC/LSM_DATE_CONVERT "

9.statements: 1. CONVERT DATE f1 INTO INVERTED-DATE f2. 2. CONVERT INVERTED-DATE f1 INTO DATE f2.

Calculates the nine's complement of the internal date format (YYYYMMDD - for more information about internal display, meaning and initial values of types and places it in the field f2.

For example, 19950511 ==> 80049488 or 80049488 ==> 19950511.

In the inverse date format, the most recent date has the numerically smallest value. You can make use of this effect when sorting dates.

10. GET TIME STAMP : returns the timestamp in short or long form. The short form contains the current date and time : DATA: s_tst TYPE timestamp, l_tst TYPE timstampl, tzone TYPE timezone. GET TIME STAMP FIELD s_tst. "Short form GET TIME STAMP FIELD l_tst. "Long form tzone = 'UTC '. "Time zone WRITE: / s_tst TIME ZONE tzone, / l_tst TIME ZONE tzone.

Then, The short form might then contain the value 19980204163520, while the long form has the value 19980204163520,1234560.

The time stamp can be converted by using CONVERT TIME STAMP and CONVERT DATE

11.Some system fields: DATLO Local date for user DATUT Global date related to UTC (GMT) TSTLO Timestamp (date and time) for user TSTUT Timestamp (date and time) related to UTC (GMT)

12. Check the site http://funciones.sapabap.cc for functions like DATE_CHECK_PLAUSIBILITY Check to see if a date is in a valid format for SAP.

Works well when validating dates being passed in from other systems.

DATE_COMPUTE_DAY Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.

DATE_GET_WEEK will return the week that a date is in.

DATE_IN_FUTURE Calculate a date N days in the future.

DAY_ATTRIBUTES_GET Return useful information about a day. Will tell you the day of the week as a word (Tuesday), the day of the week (2 would be Tuesday), whether the day is a holiday, and more.

F4_DATE for popping up calendar for date help on value request

RH_GET_DATE_DAYNAME return the day based on the date provided

RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date

RP_LAST_DAY_OF_MONTHS Determine last day of month

WEEK_GET_FIRST_DAY For a given week (YYYYMM format), this function returns the date of the Monday of that week.

Read only

Former Member
0 Likes
1,608

Hi,

You can compare them normally with simple logic as below, remove the unwanted records from the internal table those not satisfied with your condition.

For ex:

Loop at ITAB where start_date <Conditional Operator> P_start_date

and end_date <Conditional Operator> P_end_date.

--> Do Operations here.

endloop.

Thanks,

Ravi

Read only

0 Likes
1,608

Hi everybody,

Can we do date calculations like normal numeric calculations. Will symbols like >, < ,+, _ work for dates as just normal numrics...

Thanks,

Ram.

Read only

0 Likes
1,608

Yes you can work as normally... observe the result when you add, subtract...

Read only

Former Member
0 Likes
1,608

Hi,

Yes we can compare dates as normal numeric data.

See if this approach work in your case.

example:

loop at itab into wa_itab.

select ...........
........
from table..
into itab1.
where p_date_start =  wa_itab-date-start
and p_date_end =  wa_itab-date_end. 

endloop.

Hope this helps you.

plz reward if useful.

thanks,

dhanashri.