lundi 29 juin 2015

How to loop through a date range in which dates are stored as Integers?

I have to develop a system, where user will specify a starting range and an ending range (By Range, I mean to say a particular period, where PERIOD is given as a concatenation of YEAR AND MONTH). For example, PERIOD = 201304, where 2013 is the user entered Year and 04 is the MONTH. The user can specify a maximum range of upto 2 years only.

Data needs to be selected on the basis of the user entered range. The problem is whenever I try to loop through the period, the PERIOD changes after 201312 to 201313. I have separate variables for user selected year and month (start_year, start_month, end_year, end_month)

I did a IF loop there in which I tried to do the following

  FOR p_tmpyear = p_tempfrom TO p_tempto

        IF (p_monthfrm < 12) THEN
        LET p_yearfrm = p_yearfrm + 1
        LET p_monthfrm = 01
        LET p_fromperiod = p_yearfrm + 1,p_monthfrm >p_fromperiod is an integer storing concatenated Month and Year, to achieve the desired PERIOD format as mentioned above.
        LET p_tempfrom  = p_fromperiod
    END IF
    DISPLAY p_tmpyear
END FOR

I even tried thsi one :

IF (p_fromperiod MOD p_yearfrm = 13) THEN

    LET p_yearfrm = p_yearfrm + 1

    LET p_monthfrm = 01

    LET p_fromperiod = p_yearfrm + 1,p_monthfrm

Still the period changes after reaching 201212 to 201213. I want this to be 201301. Please help.

Aucun commentaire:

Enregistrer un commentaire