Skip to Content
avatar image
Former Member

To find if a date lies between a range

Hi Experts,

I have a custom table with fields Terms, Valid from date, Valid to date.

ex:

TextID1 Valid from 1.1.2007 till 31.06.2007

TextID2 Valid from 1.1.2007 till 31.12.2007

so on and so forth,

Now if the user inputes a date like 12.10.2007, i need to pick up TextID2, how do i achieve it? ( i need to find if it lies within a range)

all help is appreciated and rewarded!!

cheers,

K

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 01, 2008 at 05:43 AM

    Hello

    parameters: p_date like sy-datum.

    select single * from your_table where ...

    and p_date ge Valid from date

    and p_date le Valid to date.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 05:45 AM

    Hi Ken ,

    Check this Function Function module

    TTE_CHK_DTRNG_DATERANGE

    Check if a given date range overlap somehow with a given second

    TTE_CHK_DTRNG_DATETAB

    Checks the consistency of a complete date range table

    TTE_CHK_DTRNG_DATETAB_2

    Checks a new date range against correct date-range-table

    TTE_CHK_DTRNG_GAPS_IN_DATETAB

    Checks the consistency and time gaps of a complete date range table

    Regards,

    Sandeep

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 06:14 AM

    data : V_DATE type date.

    " HERE U CAN USE TABLE FIELD ENISTEAD OF V_DATE."

    ranges: TextID1 FOR V_DATE,

    TextID2 FOR V_DATE.

    TextID1-sign = 'I'.

    TextID1-option = 'BT'.

    TextID1-low = '01/01/2007'.

    TextID1-high = '31/06/2007'.

    append TextID1.

    TextID2-sign = 'I'.

    TextID2-option = 'BT'.

    TextID2-low = '01/01/2007'.

    TextID2-high = '31.12.2007'.

    append TextID2.

    IF '12.10.2007' IN TextID1.

    WRITE: 'BC1'.

    ELSE.

    WRITE: 'BC2'.

    ENDIF.

    USE THIS CODE AND MAKE CHANGES ACCORDING UR DESIER OUTPUT

    Edited by: anil chaudhary on Sep 1, 2008 8:15 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 06:16 AM

    Hi,

    You can try this type of logic

    REPORT z_sdn.
    
    SELECT-OPTIONS:
      s_date1 FOR sy-datum MODIF ID dat,
      s_date2 FOR sy-datum MODIF ID dat.
    
    PARAMETERS:
      p_date TYPE sy-datum.
    
    
    INITIALIZATION.
    
      s_date1-low  = '20070101'.
      s_date1-high = '20070631'.
      APPEND s_date1.
    
      s_date2-low = '20070101'.
      s_date2-high = '20071231'.
      APPEND s_date2.
    
    
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF screen-group1 = 'DAT'.
          screen-input = 0.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    
    START-OF-SELECTION.
    
      IF p_date IN s_date1.
        WRITE: / 'Date in Range1'.
      ELSEIF p_date IN s_date2.
        WRITE: / 'Date in Range2'.
      ELSE.
        WRITE: / 'Date Outside Range'.
      ENDIF.
    

    Regards

    Abhijeet

    Add comment
    10|10000 characters needed characters exceeded