Consulting

Results 1 to 13 of 13

Thread: Solved: How to format workday end date with 17:00

  1. #1
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location

    Solved: How to format workday end date with 17:00

    Hi
    I´m having difficulties to the following:

    I have a sheet with workday formula - e.g., in "M22", WORKDAY(L22;K22;Holiday) - that I thought it worked properly since I discovered that M22 format is dd/mm/yy 0:00, instead of dd/mm/yy 17:00.

    Obviously, L22 is the start date (formated dd/mm/yy 8:00) and K22 the number working days.

    How do I format the end date with 17:00?

    Thanks very much in advance
    Ioncila

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =WORKDAY(L22;K22;Holiday)+MOD(L22;1)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    Thanks for your reply.
    It did change something. By your suggestion, M22 format changed to dd/mm/yy 8:00. But still I wish it could be 17:00 for a calculation that matches the result I want.
    What is missing in formula?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is in L22 and K22?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    L22 is the start date and K22 is the number of working days.

    L22 format is dd/mm/yy 8:00. K22 format is general
    For the goal result I want, M22 format must be dd/mmm/yy 17:00.

    Formula M22 = WORKDAY(L22;K22;Holiday):

    L22 = 06/05/11 8:00
    K22 = 2
    Result in M22 must be 07/05/11 17:00

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't get why M22 should be 17:00 when L22 is 08:00.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    Considering a workday = 08:00 to 17:00,
    For example if I count 2 workdays fro 06/05/11 08:00, it should result 07/05/11 17:00, but what happens actually is 08/05/11 08:00.

    Please see the attached file.

    Thanks
    Ioncila
    Attached Files Attached Files

  8. #8
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    The workday function only uses whole days. You can't get partial days. What if you say you start something at 14:00 for 1.5 days are you wanting that to go into the next day or the day after?
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  9. #9
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    [vba]Function workdaystime(StartDate As Date, WorkDays As Double, Optional StartTime, Optional EndTime, Optional Holidays)
    If IsMissing(StartTime) Then StartTime = TimeValue("09:00")
    If IsMissing(EndTime) Then EndTime = TimeValue("17:00")
    Dim WorkingTime As Date
    Dim DateTemp As Date
    Dim TimeTemp As Date
    Dim Days
    Dim PartDays
    Dim InitialTime As Date

    Days = Int(WorkDays) - 1
    PartDays = WorkDays - Days


    WorkingTime = EndTime - StartTime
    PartDays = WorkingTime * PartDays
    InitialTime = TimeValue(StartDate)
    If InitialTime = 0 Then
    InitialTime = StartTime
    End If



    TimeTemp = InitialTime + PartDays
    If TimeTemp > 1 Then
    Days = Days + 1
    TimeTemp = TimeTemp - 1
    End If


    If IsMissing(Holidays) Then
    DateTemp = WorksheetFunction.WorkDay(StartDate, Days)
    Else
    DateTemp = WorksheetFunction.WorkDay(StartDate, Days, Holidays)
    End If

    If TimeTemp > EndTime Then
    TimeTemp = TimeTemp - EndTime
    TimeTemp = StartTime + TimeTemp
    If IsMissing(Holidays) Then
    DateTemp = WorksheetFunction.WorkDay(DateTemp, 1)
    Else
    DateTemp = WorksheetFunction.WorkDay(DateTemp, 1, Holidays)
    End If

    End If

    If TimeTemp < StartTime Then
    TimeTemp = StartTime + TimeTemp
    End If


    DateTemp = DateTemp + TimeTemp
    workdaystime = DateTemp




    End Function

    [/vba]
    This udf should work for you. I have attached yourspreadsheet with the formulas to compare. If any of you super experts want to check for anything I haven't thought of that would be cool. This might be useful as a KB entry as I have seen this sort of request before.
    Attached Files Attached Files
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  10. #10
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    That's it. It solved my problem.

    Thank you very much Brian.

  11. #11
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Your welcome
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I still don't get it. Just as 24:00 on say 3rd May is the same instant of time as 00:00 on 4th May, your situation suggests to me that 4th May 17:00 is the end of one day and 5th May 08:00 is the start of the next, so in working day terms they are the same instant of time. So I cannot see why 2 days beyond 3rd May 08:00 is not 5th May 08:00. What is 2 days beyond 3rd May 09:00?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Porto, Portugal
    Posts
    180
    Location
    Quote Originally Posted by xld
    I still don't get it. Just as 24:00 on say 3rd May is the same instant of time as 00:00 on 4th May, your situation suggests to me that 4th May 17:00 is the end of one day and 5th May 08:00 is the start of the next, so in working day terms they are the same instant of time. So I cannot see why 2 days beyond 3rd May 08:00 is not 5th May 08:00. What is 2 days beyond 3rd May 09:00?
    Hi
    I just saw your post today. So sorry for the late reply.

    In fact, I had the same understanding about the terms of a working day. However, I discovered that there were differences when comparing or copying data from MS PROJECT to MS EXCEL.
    For the work I do, I use both applications and the part of data developed in EXCEL stems from data created in Project. It was then that I realized that some dates were not the same match.

    This was the reason of the posted issue.

    Thank you all very much for the help

    Cheers
    Ioncila

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •