?
Solved

Date calculation, vb.net

Posted on 2011-05-09
2
Medium Priority
?
415 Views
Last Modified: 2012-05-11
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
Comment
Question by:chkueh
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 35718131
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
 

Author Comment

by:chkueh
ID: 35799236
Thanks for your help, Dhaest...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question