-
Apr 16th, 2008, 07:51 AM
#1
Thread Starter
Member
Help on Date Validation
Date1 = 4-10-2008
Date2 = 4-14-2008
I want to count the number of days from date1 to date2... My problem is i want to count only working days not to include Sunday and Saturday... How do i know if the date falls on Saturday and Sunday? Thnks
-
Apr 16th, 2008, 08:43 AM
#2
Member
Re: Help on Date Validation
-
Apr 24th, 2008, 08:24 PM
#3
Thread Starter
Member
Re: Help on Date Validation
here is my code:
Dim nCount As Integer, i As Integer
Dim dFrom As Date, dTo As Date
Dim temp As Date
Dim nDay As Integer
If IsDate(txtdFrom.Text) Then
txtdFrom.Text = Format(txtdFrom.Text, "DD-MMM-YY")
If IsDate(txtdTo.Text) Then
txtdTo.Text = Format(txtdTo.Text, "DD-MMM-YY")
dFrom = txtdFrom.Text
dTo = txtdTo.Text
Do Until dFrom = dTo
dFrom = dFrom + 1
temp = Format(dFrom, "DDD")
If temp = "Sat" Then
nCount = nCount
Else
nCount = nCount + 1
End If
Loop
nDay = (dTo - dFrom) + 1
txtLeaveDays.Text = nDay - nCount
End If
End If
i got an error data type mismatch [If temp = "Sat" then]
any help pls?
-
Apr 24th, 2008, 09:35 PM
#4
Re: Help on Date Validation
because your temp variable is declared as a Date, yo ucan't shove a string into it.
Look at the msdn sample given to you, there is a property DayOfWeek which tells you in enumerator form, which day it is, therefore you could just do a loop, keep adding a day to the date, and checking if it is a weekend or not.
I was bored so here you go, i wrote a function, according to it there are 2 business days between the dates you mentioned, is that right?
Code:
Private Function GetBusinessDays(ByVal date1 As Date, ByVal date2 As Date) As Integer
If date1 > date2 Then 'shuffle dates to make sure date2 is the biggest
Dim date3 As Date = date1
date1 = date2
date2 = date3
End If
'loop, adding days to the date until it matches date2
Dim bDays As Integer = 0
Do While date1 < date2
date1 = date1.AddDays(1)
If Not (date1.DayOfWeek = DayOfWeek.Saturday Or date1.DayOfWeek = DayOfWeek.Sunday) Then bDays += 1
Loop
Return bDays
End Function
-
Apr 24th, 2008, 10:00 PM
#5
Thread Starter
Member
Re: Help on Date Validation
how do i code this in visual basic 6.0... i think this code is for .net... can u help pls in vb6.. Thnks
-
Apr 24th, 2008, 10:04 PM
#6
Thread Starter
Member
Re: Help on Date Validation
im doing an online leave application... Now if u file a leave between two dates it should validate if it falls on sat or sun... If it falls on weekend the counting of days should not be included.
Urgent help ...
-
Apr 24th, 2008, 10:10 PM
#7
Re: Help on Date Validation
There is a VB6 forum, this is the VB.NET forum
http://www.vbforums.com/forumdisplay.php?f=1
-
Apr 25th, 2008, 12:00 AM
#8
Thread Starter
Member
Re: Help on Date Validation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|