VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 307,118 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,986 people online right now. Registration is fast and FREE... Join Now!




adding 20 working days to today()

 

adding 20 working days to today()

ANDRIESP

23 Sep, 2009 - 04:08 AM
Post #1

New D.I.C Head
*

Joined: 3 Aug, 2009
Posts: 1

Hey all you clever people out there

I'm rather new to this and I'm using vb.net in visual studio 2005
and I want to add 20 WORKING days to the TODAY() value.

I'm able to add the days, but it also adds NON-WORKING days.

Thanx in advance
AP biggrin.gif

Here's my code:

CODE

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Dim instance As DateTime = Now()
        Dim value As Double
        Dim returnValue As DateTime
        Dim datNewDate As DateTime = AddWorkingDays(Today, +20)
        'MessageBox.Show("The last working day was " & datNewDate)
        TextBox1.Text = Today
        If TextBox1.Text = New Date Then
            dateindev.Text = TextBox1.Text + instance.AddDays(20)
        End If
        returnValue = instance.AddDays(20)
        dateindev.Text = returnValue
        Me.dateindev.Text = returnValue.ToLongDateString
    End Sub



    Public Function AddWorkingDays(ByVal DateIn As DateTime, _
           ByVal ShiftDate As Integer) As DateTime
        ' Adds the [ShiftDate] number of working days to DateIn
        Dim datDate As DateTime = DateIn.AddDays(ShiftDate)
        ' Loop around until we get the need non-weekend day
        While Weekday(datDate) = 1 Or Weekday(datDate) = 7    
             datDate = datDate.AddDays(IIf(ShiftDate < 0, -1, 1))
        End While
        Return datDate
    End Function



User is offlineProfile CardPM
+Quote Post


JackOfAllTrades

RE: Adding 20 Working Days To Today()

23 Sep, 2009 - 10:59 AM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,321



Thanked: 454 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Moving to VB.NET
User is online!Profile CardPM
+Quote Post

AdamSpeight2008

RE: Adding 20 Working Days To Today()

23 Sep, 2009 - 12:01 PM
Post #3

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
The algorithm is slightly wrong.
It should be
PseudoCode

While DayCount>0
Advance Date by One
IF Date Is A Working Day Then
Decrement DayCount
End If
EndWhile

There also this: Next Working Day Snippet
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:33PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month