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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate date omitting Sat & Sunday

Status
Not open for further replies.

Iver

Technical User
Sep 17, 2002
4
US
Calculate future date from today, using business days only
 
Try aomething like this
tinput = @ get number of days to advance
tholdays = tinput
FOR ;
tloop = 0 TO tinput
IF ;
CDOW(DATE() + tloop) = "Saturday" OR ;
CDOW(DATE() + tloop) = "Sunday"
tholdays = tholdays + 1
ENDIF
ENDFOR

Newdate = DATE() + tholdays

Hope it works for you!

Gilesy
 
Another similar approach would be:

* --- Somewhere prior, determine New Future Date ---
m.dStartDt = {07/25/03} && Beginning Date
m.nNoWks = 5 && Number of Weeks to Advance
m.nDaysPerWk = 7
m.dNewDate = m.dStartDt + (m.nNoWks * m.nDaysPerWk)


* --- Check Resultant Day-of-Week ---
IF DOW(m.dNewDate) = 1 OR DOW(m.dNewDate) = 7
IF DOW(m.dNewDate) = 1
* --- Sunday, Advance 1 day ---
m.dNewDate = m.dNewDate + 1
ELSE
* --- Saturday, Advance 2 days ---
m.dNewDate = m.dNewDate + 2
ENDIF
ENDIF

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Here's a simple function that will gove you the total number of work days within two dates inclusive. To make it exclusive either on the start_date or end_date, just increase the start_date by one, or decrease the end_date by one respectively.

************************
function cal_days
************************
para start_date, end_date
private total
total=0
do while start_date<=end_date
if dow(start_date)#1.and.dow(start_date)#7
total=total+1
endif
start_date=start_date+1
enddo
return total

Hope this helps.


B&quot;H
Brak
 
Try this
Fdte = date() + 1
do while dow(fdte)=1 or dow(fdte)=7
fdte = fdte + 1
enddo
 
Guys,

You should also consider holidays when calculating for business days. Check out this FAQ:
faq184-307

Medic
 
Oops! Sorry, wrong forum.
I thought I was in VFP. :~/ :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top