Determine names of months between two dates - Resolved !!!!

Determine names of months between two dates - Resolved !!!!

Postby Silvio.Falconi » Tue May 11, 2021 8:31 am

I would like to determine the name of the months that are in a date range
I made a function that determines this only that I have encountered an anomaly
when I insert the price list n. 2 which concerns the low season should give me back the month of "May", "June" and "September"
however the function gives me back only "June" and "September" obviously skipping the month of "May"
for ease I have not published the archives ( listini.dbf and periodi.dbf) but I have created small arrays just to try the test aPeriodi and aListini

how is it possible that the month of may is not considered?

the test
Code: Select all  Expand view



#include "fivewin.ch"


Function test()

    local aStagione_Dates :={}
    local dDateFrom,dDateTo
    local aMesi :={}
    local nlistino := 2


     Local cYear :="2021"
     Local alistini := { ;
                       {"Stagionale ","99"}, ;
                       {"Alta Stagione","01"}, ;
                       {"Bassa Stagione","02"},;
                        {"Media Stagione","03"}}
     Local aPeriodi := { ;
                    {"17/05/"+cYear,"31/05/"+cYear,"Bassa Stagione","02",0},;
                    {"01/06/"+cYear,"30/06/"+cYear,"Bassa Stagione","02",0},;
                    {"01/07/"+cYear,"31/08/"+cYear,"Alta Stagione","01",0},;
                    {"01/09/"+cYear,"20/09/"+cYear,"Bassa Stagione","02",0} }



       SET DATE ITALIAN
       SET CENTURY ON
       SET DELETED ON

    //xbrowser aPeriodi  TITLE "periodi"

                   ASort( aListini, , , { | x, y | x[1]< y[1] } )

          //xbrowser alistini  TITLE "Listini"


          aStagione_Dates := aMesiStagione()
          dDateFrom  := aStagione_Dates[1]
          dDateTo    := aStagione_Dates[2]

             aMesi   := Determina_Mesi(dDateFrom,dDateTo,aPeriodi,aListini[nListino][2])

                   xbrowser aMesi   TITLE "Months that are in the price list "+ltrim(str(nlistino))



return nil

//------------------------------------------------------------------------------------------------------//

Function Determina_Mesi(dDateFrom,dDateTo,aPeriodi,cListino)
          local aStagione_Dates:= aMesiStagione()
          local aMesi_Ok :=  {}
          local aMesi    :=  {"Gennaio","Febbrario","Marzo","Aprile","Maggio",;
                              "Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"}
          local  cMese:=""
          local n

            dStagioneMin := aStagione_Dates[1]
            dStagioneMax := aStagione_Dates[2]


                  For d = dDateFrom to dDateTo
                     IF d >=dStagioneMin .and. d <= dStagioneMax
                             For n=1 to len(aPeriodi)
                                IF d >= ctod(aPeriodi[n][1]) .and. d <= ctod(aPeriodi[n][2])
                                   IF alltrim(cListino) = alltrim(aPeriodi[n][4])
                                      If aMesi[month(d)]  !=cMese
                                       aadd(aMesi_Ok , {aMesi[month(d)],month(d)}) // mese e numero
                                      endif
                                   endif
                                   cMese:= aMesi[month(d)]
                                 endif
                               Next
                        endif
                    next
return aMesi_Ok
//----------------------------------------------------------------------------------------------------------//
  function TakeOffExt(cFile)

   local nAt := At(".", cFile)

   if nAt > 0
      cFile := Left(cFile, nAt-1)
   end if

   return cFile

//------------------------------------------------------------------------------------------------------//

Function aMesiStagione()
          local aStagione:={}
          local cIniFile :=TakeOffExt( GetModuleFileName( GetInstance() ) ) + ".ini"
          local nAnno:= year(date())
          Local dBassa1   := GetPvProfString("Stagioni", "BASSA1","17.05."+ltrim(str(nAnno)), cIniFile)
          Local dBassa4   := GetPvProfString("Stagioni", "BASSA4","20.09."+ltrim(str(nAnno)), cIniFile)
          local dStagioneMin:= CTOD(dBassa1)
          local dStagioneMax:= CTOD(dBassa4)
          AaDd( aStagione, dStagioneMin)
          AaDd( aStagione, dStagioneMax )

          *xbrowser  aStagione
return aStagione
//------------------------------------------------------------------------------------------------------//
 
Last edited by Silvio.Falconi on Tue May 11, 2021 7:51 pm, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Determine names of months between two dates

Postby nageswaragunupudi » Tue May 11, 2021 5:57 pm

I would like to determine the name of the months that are in a date range


Assumiing d2 >= d1 and difference between d1 and d2 is <= 12 months, use this function
Code: Select all  Expand view
function MonthsInRange( d1, d2 )

   local m1 := MONTH( d1 )
   local m2 := MONTH( d2 )
   local m, aMonths  := {}

   if m1 > m2; m2 += 12; endif

   for m := m1 to m2
      AAdd( aMonths, NTOCMONTH( If( m > 12, m - 12, m ) ) )
   next

return aMonths
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Determine names of months between two dates

Postby Silvio.Falconi » Tue May 11, 2021 7:13 pm

nageswaragunupudi wrote:
I would like to determine the name of the months that are in a date range


Assumiing d2 >= d1 and difference between d1 and d2 is <= 12 months, use this function
Code: Select all  Expand view
function MonthsInRange( d1, d2 )

   local m1 := MONTH( d1 )
   local m2 := MONTH( d2 )
   local m, aMonths  := {}

   if m1 > m2; m2 += 12; endif

   for m := m1 to m2
      AAdd( aMonths, NTOCMONTH( If( m > 12, m - 12, m ) ) )
   next

return aMonths
 



Nages,

I have an archive (aListini) which corresponds to the type of price list

High season with code 01
Low Season with code 02
Mid season with code 03


Then I have an archive with the periods (aperiodi) where I determine the date intervals relative to the seasons (aListini)

from 17/05 / to 31/05 / with code 02 (low season)
from 01/06 / to 30/06 / with code 02 (low season)
from 01/07 to 31/08 with code 01 (High season)
from 01/09 to 20/09 with code 02 (low season)


If I select "High Season" the procedure must check which months exist in the archive aPeriodi
with the code 01 because 01 is the "High season" code

he should give me back in July and August

If I select "Low Season" the procedure has to check which months exist in the archive aPeriodi
with the code 02 because 02 is the "Low season" code

he should give me back in May, June, September


In the function I am trying to do if I select the price list 01 it returns me July and August.
If I select 02 it returns me only June and September while it should also return me May.


I can't do a do case or an if
of the type

IF nListino = 1

..... names of mounth

elseif Price list = 2

..names of mounth

endif

because I don't know what the date ranges are, they could be more varied and there could be more price lists
I must find the name of the months against the list number

Nages, your function MonthsInRange (d1, d2) returns me all the Months

for a sample : aMesi1 := MonthsInRange( ctod(17/05/2021"), ctod("20/09/2021")

return me May,June,July,August, September

But I wish only the mounth from they are of pricelist number 02

and I can find them by going to check the array aPeriodi

I hope You understood me
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Determine names of months between two dates - Resolved !!!!

Postby Silvio.Falconi » Tue May 11, 2021 7:31 pm

Nages, I correct your function with

Code: Select all  Expand view


 aMesi1   :=  MonthsInRange( dDateFrom, dDateTo,aPeriodi,aListini[nListino][2] )
       

 xbrowser aMesi1


function MonthsInRange( d1, d2, aPeriodi ,cListino)

   local m1 := MONTH( d1 )
   local m2 := MONTH( d2 )
   local m, aMonths  := {}

   if m1 > m2; m2 += 12; endif

      for m := m1 to m2
         For n=1 to len(aPeriodi)
            IF m >= MONTH(ctod(aPeriodi[n][1])) .and. m <= MONTH( ctod(aPeriodi[n][2]))
                    IF alltrim(cListino) = alltrim(aPeriodi[n][4])
                        AAdd( aMonths, NTOCMONTH( If( m > 12, m - 12, m ) ) )
                     Endif
               endif
            next
        next
return aMonths

 


now it might just go back to me in the English language month

Image


thanks now Is correct

Image
the second item of array , the numbers of Mouth, need me for a get :)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests

cron