MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 23rd, 2002, 06:25 AM   #1
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
My time is in four digit format with no colon.
0600
0715
2345
ect...

The value I am trying to get is hours worked expressed as a decimal...

For example:

2315 starting time
0730 ending time

Formula would display:
8.25

I know beggars can't be choosers, but I would prefer an answer in VBA, but will gladly take an excel in the cell answer!

Thanks!
Tom Schreiner is offline   Reply With Quote
Old Mar 23rd, 2002, 06:53 AM   #2
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-03-23 05:25, TsTom wrote:
Hi
My time is in four digit format with no colon.
0600
0715
2345
ect...

The value I am trying to get is hours worked expressed as a decimal...

For example:

2315 starting time
0730 ending time

Formula would display:
8.25

I know beggars can't be choosers, but I would prefer an answer in VBA, but will gladly take an excel in the cell answer!

Thanks!
If your text-formatted times are always 4-digits, the following would do what you want.

in C2 enter: =(LEFT(A2,2)&":"&RIGHT(A2,2))+0
in D2 enter: =(LEFT(B2,2)&":"&RIGHT(B2,2))+0

in E2 enter: =(D2+(D2
where A2 houses a 4-digit start time and B2 a 4-digit end time.

You could also, if desired, plug in C2 and D2 in the formula of E2.

Aladin


[ This Message was edited by: Aladin Akyurek on 2002-03-23 05:55 ]
Aladin Akyurek is offline   Reply With Quote
Old Mar 23rd, 2002, 07:16 AM   #3
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

2315 0730 = 8.25
0730 1500 = 7.50
0800 1720 = 9.33
2359 0059 = 1.00
0001 2301 = 23.00
1550 1450 = 23.00

All perfect!
Thanks Aladin!

Would you walk another mile with me for two more questions?

in C2 enter: =(LEFT(A2,2)&":"&RIGHT(A2,2))+0
in D2 enter: =(LEFT(B2,2)&":"&RIGHT(B2,2))+0
in E2 enter: =(D2+(D2

Why the +0 on the ends of the first two?
I do not understand the third???
Especially (D2 Thanks. I appreciate and hope that I might return the favor someday. Though looking at your posts, it might be a while!


[ This Message was edited by: TsTom on 2002-03-23 06:17 ]
Tom Schreiner is offline   Reply With Quote
Old Mar 23rd, 2002, 07:46 AM   #4
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-03-23 06:16, TsTom wrote:
2315 0730 = 8.25
0730 1500 = 7.50
0800 1720 = 9.33
2359 0059 = 1.00
0001 2301 = 23.00
1550 1450 = 23.00

All perfect!
Thanks Aladin!

Would you walk another mile with me for two more questions?

in C2 enter: =(LEFT(A2,2)&":"&RIGHT(A2,2))+0
in D2 enter: =(LEFT(B2,2)&":"&RIGHT(B2,2))+0
in E2 enter: =(D2+(D2

Why the +0 on the ends of the first two?
I do not understand the third???
Especially (D2 Thanks. I appreciate and hope that I might return the favor someday. Though looking at your posts, it might be a while!

[ This Message was edited by: TsTom on 2002-03-23 06:17 ]
+0 coerces (forces) Excel to treat here the result of the formula as number. The existence of ":" makes Excel to recognize the result as time.

(D2
07:30 is represented internally as 0.3125.
23:15 as 0.96875.

1.3125 - 0.96875 = 0.34375,

which is the internal value of 8:15.

8:15*24 converts 8:15 to decimal hours.

Aladin

[ This Message was edited by: Aladin Akyurek on 2002-03-23 06:49 ]
Aladin Akyurek is offline   Reply With Quote
Old Mar 23rd, 2002, 08:44 AM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Thanks again Aladin.
Tis in me notes.
Have a good day!
Tom Schreiner is offline   Reply With Quote
Old Mar 23rd, 2002, 09:24 AM   #6
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Hi Aladin:
Following up with a notes of THANKS from TsTom on your very insightful postings, I have a comment/question for you.
Incorporation of D2 minus C2 in the formula adds tremendous value ... but naturally it will be limited to a 24 hour cycle.
If I go beyond the 24 hour cycle ... say I start working on 3/23/02 11:30 and stop work on 3/25/02 7:30, I have no choice but to include the date along with the time, and follow up with normal subtraction. I don't know if it is even relevant here but I thought I might mention it anyway.
Regards!

_________________
Yogi Anand
Edit: Deleted reference to inactive web site from signature line

[ This Message was edited by: Yogi Anand on 2003-01-19 18:48 ]
Yogi Anand is offline   Reply With Quote
Old Mar 23rd, 2002, 10:59 AM   #7
Brian from Maui
Board Regular
 
Brian from Maui's Avatar
 
Join Date: Feb 2002
Posts: 7,743
Default

Aloha,

I posted this question yesterday, and I'll try again. Our company deals in military time also. We (not personally) keeps a log, and one of the major complaints is inputting the colon. Using the custom format 00:00, they can't add/subtract times. Is it possible for a macro to add the colons and still be able to add/subtract. I'm not looking for someone to write the code, just if it's possible.

Brian
Brian from Maui is offline   Reply With Quote
Old Mar 23rd, 2002, 11:37 AM   #8
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

Hi Brian

ermm.. yep VBA im sure more of lett anything can be done this wioll be none to complex for a proper programmer, so input time as 6:26 or however and then VBA can convert to whatever you want. the subtaaction part is a case of making the time usable in math (Hey an American word) so you can calculate with it, this lies the problem.

VBA would add columns convert as many times as needed and remover the now redundant columns used in convertion...

thats the idea...

You can in Excel use custom functions, know mostly as UDF (user definded function) say =SUM(... this might be =JACK( notice JACK in not in excel so we write a function to do WHATEVER we like... normal to convert data not so much math it.

OK UDF are VERY VERY VERY slow, as they are normally set to target or range settings and so will be a nasty little thing to speed up.

Saying that i have a few, if you like i can email you, bounce me a mail to work to remind me and ill set a sheet with some goodies in, convertions most or add something and remove something...

I find in Excel most this can be done of this nature in open play.. Aladin the formula mistro has been posting an even without checking and testing his work i know it perfection, and a good start.

If i was asked to make VBA in this i would convert Adadins answer in to a UDF or command button and use range settings, this would give cell or row/column of cleaned data...

i would not deviate from Aladins answers as i know form nearly 2 years of trying to beat this answers its pointless.

Its worth adding that fast codes against efficent codes and simple scripts do not mean they are the BEST.. i honest beleive its about exceptable resultys and this includes time.

I have Script taht adds col converts add something the the string and copies and pastes as value and delets the original col ... how fast???

OK 65500 cells in less than a second.

IN UDF that same codes take????

As long as it takes to copy paste and calculate... 5 seconds//////

Does it matter?

to me depends how i feel....... i happen to like a pop up saying a message to lost pals friends that have died so i remember them, or i love to type =Jack_Convert(

just me.

Take care friend...

__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old Mar 23rd, 2002, 11:53 AM   #9
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Quote:
On 2002-03-23 09:59, Brian from Maui wrote:
Aloha,

I posted this question yesterday, and I'll try again. Our company deals in military time also. We (not personally) keeps a log, and one of the major complaints is inputting the colon. Using the custom format 00:00, they can't add/subtract times. Is it possible for a macro to add the colons and still be able to add/subtract. I'm not looking for someone to write the code, just if it's possible.

Brian
Hi Brian:
We discussed this in yesterday's post that started with CJ, and we looked at a number of ways of doing this including using the custom format as you stated here. The custom format 00:00 works with numbers only, so there is a problem applying it with times with trailing 0's ... in which case there will be only 1 digit in the hours. So that will have to be taken into account.
However, as discussed at the tailend of yesterday's thread, you can convert your time entry '0830 into time by
'0830 =time(left(a2,2),right(a2,2),0))
and then you can use the new entry to add / subtract, or whatever.
If I had '0830 in cell A2, and '0600 in B2
'0830 - '0600 in cell C2 ... result formula
=time(left(a2,2),right(a2,2),0)-time(left(b2,2),right(b2,2),0)
=2:30:00
then if you want to format this as hours in decimal notation
=(a2-b2)/24 formatted as NUMBER|General gives
=2.5

HTH
Please post back if it works for you ... otherwise explain a little further and let us take it from there!

_________________
Yogi Anand
Edit: Deleted inactive web site reference from hard coded signature

[ This Message was edited by: Yogi Anand on 2003-01-19 15:49 ]
Yogi Anand is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:55 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes