TimeSerial not giving expected result

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I'm attempting to use TimeSerial to add minutes and seconds and finding a few problems e.g.

12,00,45 + 00,00,10 result in 12,12,00 instead of 12,00,55

02,45 + 01,10 gives 12,03,55. This is adding 12 hours - why is that ?

Thinking it may need the hour it was added. Then 00,02,45 + 00,01,10 gives 12,00,03.

Microsoft say it's TimeSerial(hour, minute, second) but obviously that's not for addition purposes.

Any help appreciated?

Thanks, ABB
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How exactly are you doing this and how are you representing the time values?

If I try this in the Immediate window it gives the correct result, 00:12:45, albeit with an unneeded date part.
Code:
?TimeSerial(12,0,45)+TimeSerial(12,12,0)
 
Upvote 0
Norie, even more confusing, for me that gives 31/12/1899 12:12:45 a.m.

It's the hh bit that's going silly. I want to add up a series of nn:ss and pass in the Accumulated time and time-to-add as two strings.
I then convert these to variants for TimeSerial use. (It seemss more correct to keep them as Times but Times seem to be integral to Dates, which is not correct in this case)
The hours part is needed as some totals will be > 60 minutes.
 
Upvote 0
Sorry, I don't quite follow.

If you have times as strings you should be using TimeValue.

As for date and time being integral, in Excel they are.

Date/time values are stored as numbers, with the integer part if the number being the date and the decimal part the number.

Oh, and 31/12/1899 is only a display issue, you can use Format you get rid.

Actually that reminds me, if you are adding times you should use [h]:mm for the format.
 
Upvote 0
I do have routines that work, but thought changing to the 'right' way would be a good idea but it looks
like these commands are some of the worst though out in Excel. Not to mention your results varying from mine e.g. square brackets here gave a type mismatch.
I tried timeValue and here's what I got

?TimeValue("2:24")+TimeValue("13:12:0")
3:36:00 p.m.
Should be 13:14:24

?TimeValue("00:2:24")+TimeValue("13:12:0")
1:14:24 p.m.
Should be 13:14:24 That was weird as sort of right, but inconsistent with further tests.

?TimeValue("2:24")+TimeValue("12:0")
2:24:00 p.m.
Should be 14:24
I sometimes regret saying things like this but its bloody stupid!!!

I also tried Format, expecting bum results and was right!

?format(TimeValue("00:2:24")+TimeValue("00:12:0"),h,nn)
12:14:24 a.m.

I'll stick with own primitive, but 100% reliable, code.
 
Upvote 0
If you only supply two parts, they're assumed to be hh:mm, not mm:ss. To me that's perfectly normal - if I see 2:45 my natural reaction is not 2 mins 45 seconds.

What are your Short Time settings in control panel (under Region options)?
 
Upvote 0
I did consider hours may be needed even if zero, and tried many tests both ways.
The Short time setting is 05/09/2014' If that is relevant I have to make it work on any variation. So maybe my way
is best. The expected answer has to be mm:ss utlimately so probably a further step needed.

Okay on your 2:45 Imagine e.g the duration of a piece of music...
So if anyone is interested, how would you code/count the duration of all tracks on one side of an LP. Into minutes and seconds only. And on any date they has or will ever exist !
 
Upvote 0
Short Time settings, not Short Date. ;)
 
Upvote 0
Ah right... but my Regional Setting show no Short Time, just Time 11:55:56 p.m.
 
Upvote 0
Well that's why you're getting am/pm returned by datevalue rather than 24 hour clock.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top