Solved

# Date calculation, vb.net

Posted on 2011-05-09
398 Views
Hi, Experts

I have problem to auto set the date for example:-

Due Date = 31-May-2011, Then Date A is 1 day before the due date, Then Date B is 2 days before Date A, Then Date C is 14 days before Due Date. How can i get the date which is exclude Sunday.

Below code is the sample code provided by CodeCruiser that previously i use in my program and now i need more advance calculation :http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_1.x/Q_25357487.html

Dim sDate As Date = Date.Parse("30/03/2010")
Dim dayCount As Integer = 10
For i As Integer = 1 To dayCount
If sDate.DayOfWeek = DayOfWeek.Sunday Then
End If
Next
MessageBox.Show(sDate.ToString)

Thanks

Regards,
chkueh
0
Question by:chkueh

LVL 53

Accepted Solution

Just put it into a function, with variable startDate and integer as days

Dim dueDate As Date = Date.Parse("30/03/2010")
Dim dateA As Date = ReturnDate(dueDate, 1)
Dim dateB As Date = ReturnDate(dateA, 2)
Dim dateC As Date = ReturnDate(dueDate, 14)
Private Function ReturnDate(ByVal startDate As Date, ByVal days As Integer) As Date
Dim sDate As Date = Date.Parse(startDate)
For i As Integer = 1 To days
If sDate.DayOfWeek = DayOfWeek.Sunday Then
End If
Next
Return sDate
End Function

0

Author Comment

0

## Featured Post

### Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
how to add IIS SMTP to handle application/Scanner relays into office 365.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…