Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date manipulation 1

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
PH
I’m beginning to think the following is not possible but perhaps someone can figure this out.
I have to work with an bean counter (accountant) who breaks months down into periods that run from the 1st of the month up to and including the first Sunday for period one, then from Monday to Sunday as period two and so on until the last period which is Monday up to the end of the month.

October 2005 periods would be…
Wed 1st to Sun 5th
Mon 6th to Sun 12th
Mon 13th to Sun 19th
Mon 20th to Sun 26th
Mon 27th to Fri 31st

Without physically building a table to cover the foreseeable future (say 10 years), how could I work this out programmatically?

At the moment I have the user selecting the year and month from a popup so I have input in character format
EG: “10-October” and “2008” or “06-June” and “2006”.

HELP!!!

Aussie Ken Philippines (Camiguin Island)
 
tilltek,

I think you meant that the periods you listed are for October 2008. Here's one of many ways you could solve this problem...
Code:
Dimension aryPeriods(1,2)
tdDate = {^2008/10/01} && or whatever month you want periods for
GetPeriods(tdDate, @aryPeriods)
DisplayPeriods(@aryPeriods)

*****************************
Procedure GetPeriods (tdDate, taPeriods)
*****************************
Local lcMonth, lcYear, ldDate, lnElement
lcMonth = Transform(Month(tdDate))
lcYear = Transform(Year(tdDate))
lnElement = 0
For lnCounter = 1 To 31
	ldDate = Ctod(lcMonth + "/" + Transform(lnCounter) + "/" + lcYear)
	If Empty(ldDate)
		Exit
	Endif
	If Dow(ldDate) = 2 Or Type("taPeriods(1,1)") != "D"
		lnElement = lnElement + 1
		Dimension taPeriods(lnElement, 2)
		taPeriods(lnElement, 1) = ldDate
	Else
		taPeriods(lnElement, 2) = ldDate
	Endif
Endfor
Endproc

*****************************
Procedure DisplayPeriods(taPeriods)
*****************************
Local lnCounter
For lnCounter = 1 To Alen(taPeriods,1)
	?Dtoc(taPeriods(lnCounter,1)) + " to " + Dtoc(taPeriods(lnCounter,2))
Endfor
Endproc

boyd.gif

SweetPotato Software Website
My Blog
 
Craig, many thanks. I posted this question about a year ago when I was working in Thailand and never saw your reply.
I,m in the Philippines now, and this solution works perfectly.

Aussie Lem Camiguin (Philippines)
 
Her's anotherone that does this in a calculating fashion instead of analyzing each day:

Code:
Local Array laPeriods[1]
Local lnYear, lnMonth
lnYear = 2005
lnMonth = 10
GetPeriods(lnYear, lnMonth, @laPeriods)
DisplayPeriods(@laPeriods)

*****************************
Procedure GetPeriods (tnYear, tnMonth, taPeriods)
   *****************************
   #Define cnWeekdays 7

   Local ldDate, ldMonthEnd
   ldDate = Date(tnYear, tnMonth, 1)
   ldMonthEnd = Gomonth(ldDate,1)-1
   Dimension taPeriods[1,2]
   taPeriods[1,1] = ldDate
   * go to first sunday of month:
   ldDate = ldDate + cnWeekdays - Dow(ldDate,2)
   taPeriods[1,2] = ldDate
   * from here it's simply adding cnWeekdays for each period
   Local lnPeriod
   lnPeriod = 2
   Do While ldDate<ldMonthEnd
      Dimension taPeriods[lnPeriod,2]
      taPeriods[lnPeriod,1] = ldDate + 1
      ldDate = ldDate + cnWeekdays
      If ldDate > ldMonthEnd
         ldDate = ldMonthEnd
      Endif
      taPeriods[lnPeriod,2] = ldDate
      lnPeriod = lnPeriod + 1
   Enddo
Endproc

*****************************
Procedure DisplayPeriods(taPeriods)
   *****************************
   Local lnCounter
   Clear
   For lnCounter = 1 To Alen(taPeriods,1)
       ? taPeriods[lnCounter,1],"to",taPeriods[lnCounter,2]
   Endfor
Endproc

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top