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 Functions

poornimal_nathan
Explorer
0 Likes
756

Hi,

I have fields of length 8 containing the date. How do i find that the date given is between another two dates of the same type?

7 REPLIES 7
Read only

Former Member
0 Likes
719

Hi,

Build a range..

RANGES: R_DATE FOR SY-DATUM.

R_DATE-SIGN = 'I'.

R_DATE-OPTION = <b>'BT'</b>.

R_DATE-LOW = SY-DATUM - 10.

R_DATE-LOW = SY-DATUM + 10.

APPEND R_DATE.

IF SY-DATUM IN R_DATE.

WRITE: / 'DATE IS WITHIN THE RANGE'.

ENDIF.

Thanks,

Naren

Read only

Former Member
0 Likes
719

If you have the dates in YYYYMMDD formats, assign them to TYPE D fields OR LIKE SY-DATUM fields. Then you can simply compare like this

IF your_date < to_date AND your_date > from_date.

ENDIF.

Read only

Former Member
0 Likes
719

you could do either

date1 type dats

date2 type dats

date3 type dats

if date1 ge date 2 and

date1 le date 3.

.....

endif

Read only

Former Member
0 Likes
719
REPORT YCHATEST.

DATA : V_DATE(8) VALUE '20060314',
         V_DATE1(8) VALUE '20060310',
         V_DATE2(8) VALUE '20060320'.

IF V_DATE LT V_DATE2 AND
   V_DATE GT V_DATE1.

  WRITE : / 'Date between 2 dates'.

ENDIF.
Read only

0 Likes
719

Hi,

I did try all that you said. It isn't working. When the data is entered, the format is ddmmyyyy. So, when i give a condition to check if the given date is b/w 2 others, it is being treated as numbers. For example, 01022012(1st Feb 2012) should be outside the range of 01012011(1st Jan 2011) and 31122011(31st Dec 2011). But the check shows that the date is in between these dates.

Read only

0 Likes
719

@ Chandrashekar: Hey thanx buddy...your method works...will try in my pgm n tell u the result...

@all: thanx everyone for your suggestions

Read only

Former Member
0 Likes
719

Hi,

Convert the date format from DDMMYYYY to the internal format YYYYMMDD

V_DDMMYYYY = '14032007'.

CONCATENATE V_DDMMYYYY4(4) V_DDMMYYYY2(2)

V_DDMMYYYY(2) INTO V_DATE.

Then build a range and converted date and then do the comparison..

Thanks,

Naren