Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Diff Date

Posted on 2008-06-25
2
Medium Priority
?
1,006 Views
Last Modified: 2008-08-26
I want to get TotalDay not to include Weekend.


DATEDIFF(d, myorderdate, sentdate) AS TotalDay  ??? This give me total includes Weekend


"select accountnumber as ACCOUNT, convert(char(10), myorderdate, 101) as Orderdate, convert(char(10), duedate, 101) as Duedate, Sentddate as ClosedDate, DATEDIFF(d, myorderdate, sentdate) AS TotalDay  from mytable...
0
Comment
Question by:VBdotnet2005
2 Comments
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21869895
Use this function to get the date difference, excluding Weekends (Saturday & sunday)

Function DiffWeekdays(ByVal datDay1 As Date, ByVal datDay2 As Date) As Long
        ' Comments  : Returns the number of weekdays between two dates
        '             The days are rounded down -- it takes 24 hours to make a day.
        ' Parameters: datDay1 - first (earlier) date/time (subtracted from datDay2)
        '             datDay2 - second (later) date/time
        ' Returns   : Number of whole business days between two dates
        '             (Returns negative days if datDay1 is after datDay2)
        '
        Dim lngDays As Long
        Dim lngWeeks As Long
        Dim datFirstDate As Date
        Dim datLastDate As Date
        Dim datNewDate As Date
        Dim intDirection As Integer

        If datDay1 < datDay2 Then
            datFirstDate = datDay1
            datLastDate = datDay2
            intDirection = 1
        Else
            datFirstDate = datDay2
            datLastDate = datDay1
            intDirection = -1
        End If

        ' Subtract weekends
        lngWeeks = ((Convert.ToInt32(datLastDate.DayOfWeek) - Convert.ToInt32(datFirstDate.DayOfWeek)) / 7)
        lngDays = lngWeeks * 5
        datNewDate = DateAdd(DateInterval.Day, (lngWeeks * 7), datFirstDate)
        While datNewDate < datLastDate
            datNewDate = DateAdd(DateInterval.Day, 1, datNewDate)
            If datNewDate <= datLastDate Then
                ' Don't count days when new day is Sunday or Saturday.
                ' (When new day is Saturday, you are actually counting Friday)
                If Weekday(datNewDate) <> 1 And Weekday(datNewDate) <> 7 Then
                    lngDays = lngDays + 1
                    MsgBox(Weekday(datNewDate) & " " & lngDays)
                End If
            End If
        End While
        DiffWeekdays = intDirection * lngDays
    End Function

Regards,
M.Raja
0
 

Accepted Solution

by:
VBdotnet2005 earned 0 total points
ID: 21880354
DATEDIFF(d, myorderdate, sentdate) -2*DATEDIFF(weeked, myorderdate, sentdate) as Totalday is the answer. It works for me. Please refund  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
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…
Suggested Courses

916 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