Solved

Diff Date

Posted on 2008-06-25
2
988 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
asp Google Map 2 92
asp.net mvc , views, hidden values ? 2 26
Can Angular be used with classic asp.net? 3 45
orderby list (from Json) 1 44
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

738 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