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

Date Accuracy Question

Status
Not open for further replies.

RITec

MIS
May 15, 2002
98
0
0
US
I have a question about accuracy.
I wrote the following script for another employee.
I was wondering if there is a better way to tell how many weekends are in this time period, as you can see I took the total number of days and divided by seven and then multiplied by two. The 36 is the number of personal and vacation days per year.
Is there like a workweek function?

Code:
dim CurDate 	'Today's date
dim Tday	'Long date
dim Tdate	'Difference between today and end date
dim hday	'Holiday's and weekends
dim wday	'Workdays left

CurDate = now	
Tday = formatDateTime(curdate, vblongdate)
tdate = datediff("d",curdate,#3/7/2010#)
hday = ((tdate/365)*36+(tdate/7*2))
wday = formatNumber((tdate - hday),decimals)

wscript.echo "Hello Employee " & vbcr & _
"Today is " & tday & vbcr & _
"You have " & tdate & " days until retirement" & vbcr & _
"But only " & wday & " are Working days"

Thanks for your help
RITec
 
If you check in some of the VBA forums (specifically the Access ones), you will find many many discussions of this issue. The solutions derived there are easily converted to vbscript.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Tom

This is what I have so far

Code:
dim CurDate 	'Today's date
dim Tday	'Long date
dim Tdate	'difference between today and end date
dim wday	'Workdays left
dim Eday	'End Date

CurDate = now	
Eday = #2/7/2010#
Tday = formatDateTime(curdate, vblongdate)
tdate = datediff("d",curdate,eday)
wday = 

formatNumber(DateDiff("d",curdate,eday)-(DateDiff("ww",curdate,eday)*2) - 

((tdate/365)*33),decimals)

wscript.echo "Hello Employee " & vbcr & _
"Today is " & tday & vbcr & _
"You have " & tdate & " days until retirement" & vbcr & _
"but only " & wday & " are Working days"

Answer is one day difference.
Is the way datediff used here right or should I look at one of the other functions out there?

Thanks for your help.


 
Have you tried to replace this:
tdate/365
By this:
tdate/365.25

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Calculating workdays is usually done by iterating over all of the days between date1 and date2. For each day, add 1 to the total days, If the day is a weekend day, add 1 to a weekend total, if the day is in a lookup list of holidays, add 1 to a holiday total. The number of work days then equals the day total minus weekends and holidays. I haven't done this in vbscript, but I will tomorrow if I get a chance.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
PHV

Using the tdate/365.25 gave me what the
DateDiff("d",curdate,eday)-(DateDiff("ww",curdate,eday)*2) gave me. I forgot about the .25 thanks.

Tom
I will try to work on what you are discribing (Just to see if I can) no doubt it will take me longer to do.





Thank you both

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top