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
Solved

DateDiff question, need count for 8 hours a day including weekends and holidays

Posted on 2008-10-15
4
490 Views
Last Modified: 2008-11-10
Should be pretty simple really, but I am in brainfart mode this am (pardon the expression), lack of caffeine again, I suppose...

I have two dates (startDate and endDate), they represent when a ticket is opened and closed.  There will be a third field to be used later for 'workTime'.  

For each day (24 hour period) in the dateDiff (including holidays and weekends), I need to add 8 hours, then when I have the final number, I need to subtract the value of the 'workTime' field.

chuck
0
Comment
Question by:cwickens
  • 3
4 Comments
 

Expert Comment

by:nmxsupport
ID: 22719992
0
 
LVL 5

Author Comment

by:cwickens
ID: 22720135
It looks like this is only available in MS Project/VBA.  I am using it in a Web App with VB,

Any thoughts on using dateDiff and converting it or a VB example of projectDateDiff?
0
 
LVL 5

Author Comment

by:cwickens
ID: 22720238
ok, I am making progress...  I can use the dateDIff and return the number of days, hours, minutes and seconds.

I get the result as 3.13:30:00  (3 days, 13 hours, 30 minutes, 0 seconds).  I need to parse that result into: 24 (3 8 hour periods) + 8 (in the 13 hour block)  + .5 (for the 30 minute) = 32.5

ugh....thoughts anyone?
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim startDate As DateTime = Me.RadStartDateTimePicker.SelectedDate
        Dim endDate As DateTime = Me.RadStartDateTimePicker0.SelectedDate
        Dim totalTime As String = ""
 
        totalTime = endDate.Date.Subtract(startDate).ToString
        Me.LabelTotalTime.Text = totalTime
    End Sub

Open in new window

0
 
LVL 5

Accepted Solution

by:
cwickens earned 0 total points
ID: 22886590
I found the solution, I am using Telerik's radControls and ended up using dateDiff along with regular math to get the values I wanted.  There is probably a better method, however, this works for what I need.
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.RadStartDateTimePicker.IsEmpty Then
            Me.LabelNoStartDate.Text = "Start Date/Time Required"
            Exit Sub
        ElseIf Me.RadStartDateTimePicker0.IsEmpty Then
            Me.LabelNoStartDate.Text = ""
            Me.LabelNoEndDate.Text = "End Date/Time Required"
            Exit Sub
        Else
            ' get start and end date values
            Dim startDate As DateTime = Me.RadStartDateTimePicker.SelectedDate.Value
            Dim endDate As DateTime = Me.RadStartDateTimePicker0.SelectedDate.Value
 
            ' calculate total event minutes
            Dim totalHours As Double = DateDiff(DateInterval.Hour, startDate, endDate)
 
            ' convert total minutes to 8 hour days
            Dim intTotalHours As Double = totalHours / 3
 
            ' get value of work hours and minutes
            Dim intWorkTime As Double = Me.TextBoxWorkTime.Text
 
            ' calculate standby time
            Dim standbyTime As String = intTotalHours - intWorkTime
 
            'check to see if value is positive
            If standbyTime < 0 Then
                Me.LabelNegativeValue.Text = "The Standby Time can not be less than '0', Please check your date/time values"
                Exit Sub
            End If
 
            Me.LabelTotalTime.Text = intTotalHours & " Total Hours"
            Me.LabelStandBy.Text = standbyTime.ToString & " Standby Time"
            Me.LabelWorkTime.Text = intWorkTime.ToString & " Work Time"
            Me.LabelNoEndDate.Text = ""
            Me.LabelNoStartDate.Text = ""
        End If
 
    End Sub

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

860 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