Welcome to the Smartsheet Forum Archives
这个论坛的帖子不再监视for accuracy and their content may no longer be current. If there's a discussion here that interests you and you'd like to find (or create) a more current version, pleaseVisit the Current Forums.
using start and end time columns to calculate hours worked for a timesheet page
Comments
-
J. Craig Williams ✭✭✭✭✭✭
Blair,
Either they enter time as 8:15 or they enter it from a drop down list.
If entering like 8:15, you'll need to parse the time into hours.
If you want to have them enter from a drop down list, it gets a little easier (because you don't have to worry about error checking bad data entries).
你会得到两个列times, one for the date, one (not seen by the user of the WebForm) to do your calculations.
There's a couple good threads on the Community to help.
Hope that gets you started.
Craig
-
Hi Craig, thanks for your reply. i like the drop down idea, that will work well. the bit i am stuck on is how i can calculate total hours worked in a day from the start and finish times. eg start 8.15 and finish 4.30. how do i change time format into number format to get me total hours worked of 8 hours and 15 minutes???
Regards
Blair
-
J. Craig Williams ✭✭✭✭✭✭
Blair,
Check this thread out:
https://community.smartsheet.com/discussion/heres-fun-one
Since you like the drop down list idea, this fits.
Craig -
Travis Employee
Here is a non-dropdown option. The user would enter the start time and end time and the third column calculates time between.
Feel free to adjust the StartTime and EndTime to test it!
Here's the formula:
=INT((((IF(LEFT(EndTime1, FIND(":", EndTime1) - 1) = "12", IF(OR(FIND("a", EndTime1) > 0, FIND("p", EndTime1) > 0), 0, 12), VALUE(LEFT(EndTime1, FIND(":", EndTime1) - 1))) + IF(FIND("p", EndTime1) > 0, 12)) * 60 + VALUE(MID(EndTime1, FIND(":", EndTime1) + 1, 2))) - ((IF(LEFT(StartTime1, FIND(":", StartTime1) - 1) = "12", IF(OR(FIND("a", StartTime1) > 0, FIND("p", StartTime1) > 0), 0, 12), VALUE(LEFT(StartTime1, FIND(":", StartTime1) - 1))) + IF(FIND("p", StartTime1) > 0, 12)) * 60 + VALUE(MID(StartTime1, FIND(":", StartTime1) + 1, 2)))) / 60) + ":" + IF(((((IF(LEFT(EndTime1, FIND(":", EndTime1) - 1) = "12", IF(OR(FIND("a", EndTime1) > 0, FIND("p", EndTime1) > 0), 0, 12), VALUE(LEFT(EndTime1, FIND(":", EndTime1) - 1))) + IF(FIND("p", EndTime1) > 0, 12)) * 60 + VALUE(MID(EndTime1, FIND(":", EndTime1) + 1, 2))) - ((IF(LEFT(StartTime1, FIND(":", StartTime1) - 1) = "12", IF(OR(FIND("a", StartTime1) > 0, FIND("p", StartTime1) > 0), 0, 12), VALUE(LEFT(StartTime1, FIND(":", StartTime1) - 1))) + IF(FIND("p", StartTime1) > 0, 12)) * 60 + VALUE(MID(StartTime1, FIND(":", StartTime1) + 1, 2)))) - INT((((IF(LEFT(EndTime1, FIND(":", EndTime1) - 1) = "12", IF(OR(FIND("a", EndTime1) > 0, FIND("p", EndTime1) > 0), 0, 12), VALUE(LEFT(EndTime1, FIND(":", EndTime1) - 1))) + IF(FIND("p", EndTime1) > 0, 12)) * 60 + VALUE(MID(EndTime1, FIND(":", EndTime1) + 1, 2))) - ((IF(LEFT(StartTime1, FIND(":", StartTime1) - 1) = "12", IF(OR(FIND("a", StartTime1) > 0, FIND("p", StartTime1) > 0), 0, 12), VALUE(LEFT(StartTime1, FIND(":", StartTime1) - 1))) + IF(FIND("p", StartTime1) > 0, 12)) * 60 + VALUE(MID(StartTime1, FIND(":", StartTime1) + 1, 2)))) / 60) * 60) < 10, "0") + ((((IF(LEFT(EndTime1, FIND(":", EndTime1) - 1) = "12", IF(OR(FIND("a", EndTime1) > 0, FIND("p", EndTime1) > 0), 0, 12), VALUE(LEFT(EndTime1, FIND(":", EndTime1) - 1))) + IF(FIND("p", EndTime1) > 0, 12)) * 60 + VALUE(MID(EndTime1, FIND(":", EndTime1) + 1, 2))) - ((IF(LEFT(StartTime1, FIND(":", StartTime1) - 1) = "12", IF(OR(FIND("a", StartTime1) > 0, FIND("p", StartTime1) > 0), 0, 12), VALUE(LEFT(StartTime1, FIND(":", StartTime1) - 1))) + IF(FIND("p", StartTime1) > 0, 12)) * 60 + VALUE(MID(StartTime1, FIND(":", StartTime1) + 1, 2)))) - INT((((IF(LEFT(EndTime1, FIND(":", EndTime1) - 1) = "12", IF(OR(FIND("a", EndTime1) > 0, FIND("p", EndTime1) > 0), 0, 12), VALUE(LEFT(EndTime1, FIND(":", EndTime1) - 1))) + IF(FIND("p", EndTime1) > 0, 12)) * 60 + VALUE(MID(EndTime1, FIND(":", EndTime1) + 1, 2))) - ((IF(LEFT(StartTime1, FIND(":", StartTime1) - 1) = "12", IF(OR(FIND("a", StartTime1) > 0, FIND("p", StartTime1) > 0), 0, 12), VALUE(LEFT(StartTime1, FIND(":", StartTime1) - 1))) + IF(FIND("p", StartTime1) > 0, 12)) * 60 + VALUE(MID(StartTime1, FIND(":", StartTime1) + 1, 2)))) / 60) * 60)
-
J. Craig Williams ✭✭✭✭✭✭
LOL
Or that.
Craig
-
Travis Employee
Its an intimidating formula! But it is easy to use, just copy it into a text editor and use find and replace to add your own start and end date cell references to it, then paste it into your sheet.
-
J. Craig Williams ✭✭✭✭✭✭
You are going to scare people.
Craig
-
thanks Travis, you are a legend!. this has worked perfectly. my next challenge however is how do i then subtract billable hours from total hours worked where total hours is created using your formula and produces a number like 8:30 being 8 hours and 30 minutes. billable hours also produces a number with the same format eg 6:15 being 6 hours and 15 minutes
-
hey Craig, you are a legend too:)
just saying
-
J. Craig Williams ✭✭✭✭✭✭
Blair,
re: comment to Travis:
This will get you the value of one of the hours
=VALUE(LEFT(Hours1, FIND(":", Hours1) - 1)) + (VALUE(RIGHT(Hours1, FIND(":", Hours1))) / 60)
Two of those together will give you the diff.
re: comment to me. You'll make me blush. But thanks.
Soapbox:
Your request to Travis is one of the reasons why I would normallly have a solution using two or more column instead of the that beautiful and horrible formula of Travis.
No matter how much we think we understand the requirements, someone always wants a bit of something that isn't in the original spec.
Using the two or more column solution, the answer would have been (probably)
=[Total Hours raw]1 - [BIllable Hours raw]1
Another reason is that there are 2762 chararacters (incuding white space) in that formula. And I know I would have mistyped one of them along the way. I'm pretty sure Travis did not build it all at once, likely used two or more columns to figure out the pieces and then combined them at the end. For me, that is extra work (the combining) for likely extra work later (figuring out what went wrong or figuring out how it works)
Once I can pick and choose which columns are hidden/unhidden quicker and more configurably (feature request), I'll be even better off.
Steps carefully off the soapbox and goes back into his cave.
Craig
-
Travis Employee
Thanks Blair, but I cannot take credit for this formula! One of our consultants,Ajay, built it.
We do have plans to add time formulas to Smartsheet, so we wont have to use these "beautiful and horrible" formulas. I dont have an eta for this but it is something we are actively working on.
-
ok Craig, have used your value formula which works great.
only thing now is how do i get it it ignore a column that has no value in it as my total only works if all three of my billable hours columns have values in them which is not always the case
-
all good travis, i am happy to use your formula for now
-
ok, so i have used the above =value formula which works really well...except where there is no value in the field that it refers to. in which case it gives the following error ... # missing or invalid parameter.
what do i need to add to the formula to prevent this from occuring when the field is blank?
Categories
HAS() will only return true under three conditions.<\/p>
- The cell is a multicontact cell and contains a match for the contact<\/li>
- The cell is a multiselect dropdown and contains a match<\/li>
- The cell is not a multicontact or multiselect dropdown and contains ONLY and EXACTLY the text you are matching against. <\/li><\/ol>
I am assuming your row in question is a standard Text\/Number cell? If so, you will need to get somewhat creative with some CONTAINS() statements.<\/p>
This will narrow down your matches to only cells that contain a space both before and after TAC. If, however, TAC can appear as the first or last \"word\" in the cell, it would not match in that circumstance as there would only be a space on one side.<\/p>
=IF(CONTAINS(\" TAC \", [Column Name1]@row), 1, 0)<\/p>
<\/p>If TAC can appear as the first or last \"word\" in the cell, this will cover those possibilities as well.<\/p>
=IF(OR(CONTAINS(\" TAC \", [Column Name1]@row), LEFT([Column Name1]@row, 4) = \"TAC \", RIGHT([Column Name1]@row, 4) = \" TAC\"), 1, 0)<\/p>
<\/p>If it is possible that TAC will be the exact entry of the cell, you will need an additional statement to cover that, as there would not be spaces on either side. This will add that option.<\/p>
=IF(OR(CONTAINS(\" TAC \", [Column Name1]@row), LEFT([Column Name1]@row, 4) = \"TAC \", RIGHT([Column Name1]@row, 4) = \" TAC\", [Column Name1]@row = \"TAC\"), 1, 0)<\/p>
<\/p>If there are other situations you may have in your sheet, i.e., TAC inside parenthesis, or before or after punctuation, etc, you will additional statements to include those options as well.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":322,"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":254,"urlcode":"Formulas","name":"Formulas"}]},{"discussionID":109146,"type":"question","name":"Identify Workflow from ID?","excerpt":"Good morning, got a random one. Is there any way to identify what sheet or workflow an automation ran from? I got a rogue automation this morning, and I don't know what sheet it lives in. However, I noticed at the bottom of the email, there is an ID number, similar to a sheet or row ID. Is there any way, maybe with the…","snippet":"Good morning, got a random one. Is there any way to identify what sheet or workflow an automation ran from? I got a rogue automation this morning, and I don't know what sheet it…","categoryID":321,"dateInserted":"2023-08-18T14:25:47+00:00","dateUpdated":null,"dateLastComment":"2023-08-19T08:29:31+00:00","insertUserID":137019,"insertUser":{"userID":137019,"name":"Samuel Mueller","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Samuel%20Mueller","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/B9G8B70WXQWC\/nKTI46EH9WQOM.jpg","dateLastActive":"2023-08-18T20:30:29+00:00","banned":0,"punished":0,"private":false,"label":"Overachievers"},"updateUserID":null,"lastUserID":161820,"lastUser":{"userID":161820,"name":"Hamza1","title":"Mr","url":"https:\/\/community.smartsheet.com\/profile\/Hamza1","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-20T04:58:20+00:00","banned":0,"punished":0,"private":false,"label":"Moderator"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":4,"countViews":48,"score":null,"hot":3384804918,"url":"https:\/\/community.smartsheet.com\/discussion\/109146\/identify-workflow-from-id","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/109146\/identify-workflow-from-id","format":"Rich","tagIDs":[227,334,448],"lastPost":{"discussionID":109146,"commentID":391519,"name":"Re: Identify Workflow from ID?","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/391519#Comment_391519","dateInserted":"2023-08-19T08:29:31+00:00","insertUserID":161820,"insertUser":{"userID":161820,"name":"Hamza1","title":"Mr","url":"https:\/\/community.smartsheet.com\/profile\/Hamza1","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-20T04:58:20+00:00","banned":0,"punished":0,"private":false,"label":"Moderator"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"Smartsheet Basics","url":"https:\/\/community.smartsheet.com\/categories\/smartsheet-basics%2B"}],"groupID":null,"statusID":3,"image":{"url":"https:\/\/us.v-cdn.net\/6031209\/uploads\/EYR2B79VH1AY\/image.png","urlSrcSet":{"10":"","300":"","800":"","1200":"","1600":""},"alt":"image.png"},"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-18T19:37:53+00:00","dateAnswered":"2023-08-18T19:10:30+00:00","acceptedAnswers":[{"commentID":391468,"body":"
Yeah. That does sound like it could take awhile. Haha. And if you knew the sheet I'd, you'd be able to just jump to it in SS instead of needing the api.<\/p>
<\/p>Maybe a product enhancement request to expand the workflow portion of the api to include the sheet id is in order.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":321,"name":"Smartsheet Basics","url":"https:\/\/community.smartsheet.com\/categories\/smartsheet-basics%2B","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":227,"urlcode":"api-and-developers","name":"API and Developers"},{"tagID":334,"urlcode":"automations","name":"Automations"},{"tagID":448,"urlcode":"workflows-in-smartsheet","name":"Workflows in Smartsheet"}]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&siteSectionID=0&sort=-hot&limit=3&expand%5B0%5D=all&expand%5B1%5D=-body&expand%5B2%5D=insertUser&expand%5B3%5D=lastUser&status=accepted","prevURL":null,"currentPage":1,"total":10000,"limit":3},"title":"Trending Posts","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">