Number of seasons between 2 dates

qwkslvr1999

Registered User.
Local time
Today, 16:27
Joined
Jan 21, 2002
Messages
42
I need to know how I can find how many seasons have lapsed between two dates. It's fairly easy if the 2 dates fall within the same year but I cannot figure out how to do it if they fall in different years. Following is how seasons are defined: season 1: 12/20-3/19; season 2:3/20-6/19; season 3:6/20-9/19; season 4:9/20-12/19.

For example, if date1=1/10/05 (falls in season 1) and date2=9/20/05 (falls in season 4), the answer will be = 3. IF date1=5/15/03 (falls in season 2) and date2=6/21/05 (falls in season 3, 2 years later), answer will be 8.

Any help will be GREATLY appreciated!!!
 
the code below should solve your problem

Code:
Function findNrSeasons(datum1 As Date, datum2 As Date) As Integer
  Dim dm1 As Integer, dm2 As Integer
  dm1 = Month(datum1) * 100 + Day(datum1)
  dm2 = Month(datum2) * 100 + Day(datum2)
  
  findNrSeasons = (Year(datum2) - Year(datum1)) * 4
  If findNrSeasons > 0 Then findNrSeasons = findNrSeasons - 1
  findNrSeasons = findNrSeasons + (sel_seas(dm2) - sel_seas(dm1))
End Function

Private Function sel_seas(val_dt As Integer) As Integer
  Dim seas As Integer
  Select Case val_dt
    Case 320 To 619
      seas = 2
    Case 620 To 919
      seas = 3
    Case 920 To 1219
      seas = 4
    Case Is >= 1220 Or val_dt < 320
      seas = 1
  End Select
  sel_seas = seas
End Function

HTH

filo65
 
Thank you very much for all the inputs!!! You're a life saver!
 

Users who are viewing this thread

Back
Top Bottom