+ Reply to Thread
Results 1 to 10 of 10

If statements for time

  1. #1
    Registered User
    Join Date
    01-28-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2016
    Posts
    43

    If statements for time

    Hello Forum,

    I am hoping that you can help me out.

    I am trying to build a timesheet for work.
    I have the employees start time in cell A1 and their end time in cell A2. In cell A3 I have their hours, which the formula I have is =sum(A2-A1) to find out the hours worked (using the 24hr clock system).

    My issue is this - I need to create an IF statement which will deduct a half hour lunch if their start or end time is 12:00:00 PM.

    Example:
    Johnny works from 8am to 5pm.
    In cell A1 entered is 08:00:00 and in cell A2 it says 17:00:00. I need the cell that calculates the hours (A3) to minus the half hour lunch at noon only IF noon is punched in.

    Sometimes they work on different projects throughout the day and I need to tally that.

    Example:

    Johnny starts at 8am and works until 10am. The formula I have now will easily calculate 2 hrs worked. Johnny starts working again at 10:30am and works until 1pm that afternoon. I now need an if statement in there to deduct a half hour for lunch.

    Any ideas anyone??
    Help is greatly appreciated!

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: If statements for time

    Maybe:

    =A2-A1-(AND(A1<0.5,A2>0.5)*1/48)

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If statements for time

    I have the employees start time in cell A1 and their end time in cell A2. In cell A3 I have their hours, which the formula I have is =sum(A2-A1) to find out the hours worked (using the 24hr clock system).
    When calculating a difference A2-A1 is sufficient. No need to add sum(...

  4. #4
    Registered User
    Join Date
    01-28-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: If statements for time

    Fantastic!!
    Worked like a charm!! Thank you! Thank you!

  5. #5
    Registered User
    Join Date
    01-28-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: If statements for time

    Found a glitch in this - it worked out great until the end time was 12:05pm.

    Example again:

    Johnny starts at 8am and ends at 12:05pm (again, using the 24hr clock) - we do not want this to minus a half hour, just the five minutes that he worked past lunch.

    so far, the formula is this:
    =A2-A1-(AND(A1<0.5,A2>0.5)*1/48)
    should there be an IF statement in there? Whereas if the time is greater than 12pm and less than 12:30pm, to only deduct the time worked and not have the formula take out a half hour.

    Help again is SO greatly appreciated!

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If statements for time

    Try this =A2-A1-(AND(A1<0,5;A2>0,5)*MIN(A2-0,5;1/48))

  7. #7
    Registered User
    Join Date
    01-28-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: If statements for time

    Quote Originally Posted by arthurbr View Post
    Try this =A2-A1-(AND(A1<0,5;A2>0,5)*MIN(A2-0,5;1/48))
    I've tried it and Excel keeps changing it to:
    =A2-A1-(AND(A1<0.5,A2>0.5)*MIN(A2-0,1:5/48))

    won't work ..=( ..

    any other suggestions?

    Your help is greatly appreciated

  8. #8
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: If statements for time

    perhaps through the formula "min" and "max" ?
    Attached Files Attached Files
    Last edited by trucker10; 09-08-2010 at 04:52 PM. Reason: insert formula arthurbr

  9. #9
    Registered User
    Join Date
    01-28-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: If statements for time

    I have attached a mock version of what I'm trying to achieve.

    Any help on this formula would be SO greatly appreciated!


    Again, much thanks!
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If statements for time

    Works perfectly for me ( see attached).( you may want to change the ; to , depending on your regional settings
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1