• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

Date calculation, vb.net

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
                    sDate = sDate.AddDays(-1)
                    If sDate.DayOfWeek = DayOfWeek.Sunday Then
                        sDate = sDate.AddDays(-1)
                    End If
                Next
                MessageBox.Show(sDate.ToString)

Thanks

Regards,
chkueh
0
chkueh
Asked:
chkueh
1 Solution
 
DhaestCommented:
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
            sDate = sDate.AddDays(-1)
            If sDate.DayOfWeek = DayOfWeek.Sunday Then
                sDate = sDate.AddDays(-1)
            End If
        Next
        Return sDate
    End Function

Open in new window

0
 
chkuehAuthor Commented:
Thanks for your help, Dhaest...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now