Excel custom format seconds as dd:hh:mm:ss but hide leading zero values - excel

Is there an Excel custom format string that will show seconds in a dd:hh:mm:ss format, but hiding any leading zero values?
E.g., it is straightforward to format 100,000 s in dd:hh:mm:ss as 01:03:46:40. However, for 50,000 seconds I would like to display as hh:mm:ss (i.e. 13:53:20) not as dd:hh:mm:ss (00:13:53:20), using a single formatting string for all values.
It can be achieved using TEXT formulas with something like:
IF(A1<60,
TEXT(A1/86400, "ss"),
IF(A1<3600,
TEXT(A1/86400, "mm\:ss"),
IF(A1<86400,
TEXT(A1/86400, "hh\:mm\:ss"),
TEXT(A1/86400, "d\:hh\:mm\:ss"))))
However this returns all values as text which doesn't allow numerical sorting of the values.
It can also be achieved with conditional formatting, but I'd prefer to use that only if I have to.
I'm hoping someone is going to tell me about the magical custom format string that will do the job!

Dates are stored as days and fractions of a day.
So, no matter what, 50,000 in Excel means 50,000 days. Before you can format it to show the equivalent hrs/mins/sec you must divide it by 86,400 to transform the value to 50,000 seconds
Once you have done that, you can use a custom number format: [<1]hh:mm:ss;dd:hh:mm:ss
However, you should also be aware the dd will only be in the range of 1-31. It will roll over back to 1 at that point. So if your time will encompass more than 31 days, you will not be able to use a custom number format to accomplish what you want.

Related

How to convert two time formats into one?

I am pulling Cross Country race times, and trying to convert the race time into an integer that can be easier to work with.
I am using the formula
=([Cell Name]-INT([Cell Name])*60*24
But I am so far retrieving two different time formats:
17:23.4
15:09
Both formats take that formula differently, and they are producing different numbers. The first format is changed into 17 minutes, but the other is turned into 1000+ minutes. Is there a way that I can convert these times into one format?
The main problem you are having is as tom sharpe pointed out is that some times are being assessed as HH:MM and others as MM:SS. if you look at your source data cell (assmue A2) and use the following formula it will tell you if you are dealing with text or time in excel serial date time formatted to appear in a manner we are used to seeing:
=ISTEXT(A2)
now assuming that the result is TRUE, this means you are dealing with TEXT. Adding a leading 0: to the text will make the time recognizable to excel as being in the format HH:MM:SS and allow for you to deal with it consistently.
To do this use the following formula:
=timevalue("0:"&A2)
Things may get a little wonky if ou have anything greater than or equal to 60 as the first two digits.
once you have it in the proper format you can then use it in your formula.

Controlling Excel time format input/output

Background: I have been officiating our local jogging events for about ten years now. I am responsible for handling the data of the participants (name, sporting club, bib number) split into their categories (age bracket+gender, distance). The main task is collecting their times, and processing that data (sorting the runners within their category etc). I can handle this with Excel mostly fine.
Problem: What is the ideal time format for entering the race times of the participants? The times are either in the format mm:ss or (for slower runners and/or longer distances) h:mm:ss. Excel doesn't seem to have a built-in format where the hours field is optional. For optimizing my workflow ideally I would like to have a cell format such that the input
47:12 is to be interpreted as 47 minutes and 12 seconds, and the input 1:09:38 is to be interpreted as 1hr 9 minutes and 38 seconds. However, Excel, with the best fitting cell format that I found, will insist that the input 47:12 means 47 hours and 12 minutes. For times exceeding 1 hour I would input 1:03:00 if I meant that the seconds field is to be left with value zero.
How to make Excel realize that when the format can handle up to three numbers as inputs, it would, when given only two numbers, move them towards the end?
Thinking: I "can" key in 47 minutes and 12 seconds as 0:47:12 all right. But because most of the times are under 1 hour, that is partly wasted effort. Also, using such a format the data is displayed on the screen together with that superfluous 0:. What's worse (IIRC) those leading zeros
also appear in the printed versions, which is strange (insulting even) in a shorter distance for junior participants.
My hack: I enter the times as general numbers in the mm,ss format (in these parts a comma serves as a decimal separator). Excel can sort those as numbers just fine. I then duplicate the data of that sorted column to another "printable" version (formatted as text), where the data is just copied, but I correct the times exceeding 60 minutes by hand. This works just fine as long as I'm not in a hurry (our event is not exactly Boston Marathon, say, less than 200 participants), and remember to hide the column that is not supposed to be printed. This is kludgy, and there have been accidents, when other officials have been rushing me to get the results printed.
I managed to create a format where the hour-field is optional. It works with a conditional format. First you format your cells as standard, so you get the times as comma-values. After that you create a conditional format for these cells, which has two rules:
if cellvalue > 0.04166667 format hh:mm:ss
if cellvalue < 0.04166666 format mm:ss
Result:
47:12
01:09:38
01:00:00
So you get what you really want and you can use the original values for sorting and so on.
EDIT:
For the input you need four additional columns. You enter the times as you want, e.g. 47:12 and 1:09:38. In the next three columns you split these values in hour, minute and second, whereby the interpretation limit is 3 hours (03:00), which is 0.125.
So, these are the formulas for the split columns (your input is in B1):
Hours: =IF(B1>0.125,0,HOUR(B1))
Minutes: =IF(B1>0.125,INT(B1)*24+HOUR(B1),MINUTE(B1))
Seconds: =IF(B1>0.125,MINUTE(B1),SECOND(B1))
And finally, you put all values togehter in the forth column:
=TIME(C1,D1,E1)
and use the conditional format above.
If you will be entering your data as
`mmm,ss`
where the comma is the decimal point, then you can convert it to "Excel Time" with the simple formula:
=DOLLARDE(A1,60)/1440
Format the result as you wish.
If you want everything displayed as h:mm:ss then use that as your custom format (Format > Cells > Number > Custom Type:...)
If you want h to be displayed only with values of 60 minutes or greater, then use
[<0.0416666666666667]mm:ss;h:mm:ss
for your cell's custom format.
Beware that seconds must be entered with two digits always. In other words
6,2 will translate to 6 min 20 sec.
6,02 will translate to 6 min 2 sec
I really like IQV's answer above, but as pointed out in the comment section, the leading zero will be required for the data entry side. If for whatever reason this is not acceptable you can use the following ugly formula to convert your time entered in your usual method of mm,ss to hh:mm:ss with the hh: being displayed as required. Unfortunately it converts the whole thing to text which means you can no longer perform math operations on it.
=IF(FIND(".",MOD(D2,60)&".")=2,"0","")&MOD(D2,60)
and since you use , as your decimal separator the formula would become:
IF(FIND(",",MOD(D2,60)&",")=2,"0","")&MOD(D2,60)
If you use ; as your list separator then your formula becomes
IF(FIND(",";MOD(D2;60)&",")=2;"0";"")&MOD(D2;60)
There are probably some cleaner formulas, but that will get you started. Just replace D2 with the location where your time is stored.
Again I still prefer IQV's answer as you can do much more with the time information when its stored as a number and not text.
Option 2
lets say you change your data storage method to hhmm,ss in cell D6. you could rip apart the information and reassemble it in a display friendly version as follows.
=IF(FIND(".",D6)<=3,LEFT(D6,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)),LEFT(D6,FIND(".",D6)-3)&":"&MID(D6,FIND(".",D6)-2,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)))
you will need to substitute your list separator for the , and then substitute a coma for the decimal.

Using this value "2016-05-12 21:51:13 -0500" in Excel

How do I work with a Date Time -0500 value?
I have a sheet that has a value that looks like this:
2016-05-12 21:51:13 -0500
I want to be about to use it.
I want to filter all records that are greater than
2016-05-12 00:00:01 -0500
But I do not know how to work with this value.
Use this formula:
=--LEFT(A1,LEN(A1)-5)
Then format it like this
yyyy-mm-dd hh:mm:ss -\0\5\0\0
Then you can copy and paste the values and formatting where you want it
You need to convert the data into Excel date/times. With data in A1 in B1 enter:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))
and format to display both date and time:
Let's presume for a moment that for some unknown reason Excel could not identify your string as a valid date time. You can always go back to basics and break your string down into its components. Let's start off and assume that your date time and offset string are in cell A1.
Step 1) Strip out the year
=left(A1,4)
Step 2) Strip out the month
=MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1)
That bad boy of a formula looks for the first - and the second - and based on that information finds the starting position to start pulling characters from and figures out how many characters to pull.
In your case we could have set it to pull two characters and had it start at character six as there is no variation to your date format. However, in a generic sense where there are not always leading zeros in the month, or sometimes you were flipping between four characters for the year and two characters for the year, the above would still work.
I am also assuming that month is the middle value (05) and you are not talking about December 5th here.
Step 3) Pull out the day
We could have used a similar approach using mid here, and again we could have hard coded it (wait, I did hard code two character return). Instead for a little flavour I used a right left sequence.
=RIGHT(LEFT(A1,FIND(" ",A1)-1),2)
Step 4) Pull out the time
Now you could go through the whole process and pull out hours, minutes and seconds, but Excel is usually pretty good at recognizing a time format as there is not much variation to it. Also this gives an opportunity to see a new formula for dealing with string manipulation.
Now since your time format was constant, I got a little lazy knowing that your time was always going to be eight characters long since your format always has a leading zero. As such, I used the following:
=TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Basically, I grabbed the whole time, HH:mm:ss, and dumped it into timevalue (note there is also a datevalue). Timevalue will attempt to convert a string in time format to Excel time format as a decimal value.
Now as previously noted, if all those times are all stamped with the same -0500, just ignore it.
To get all that date and time converted into a single cell we would take each of the date parts and drop them into the DATE function and then add the time component on. In Excel speak that looks like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Now if you want that to display with the -0500, look at Scott's answer for formatting. If you want to convert the time to local time and get rid of the -0500 then you would need to add -5 hours to the above formula which would look something like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+time(-5,0,0)
And if we were not so lazy and did not want to hard code the time, it would look more like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+TIME(LEFT(RIGHT(A1,4),2),RIGHT(A1,2),0)*IF(LEFT(RIGHT(A1,5),1)="-",-1,1)

Excel date formatting convert to number

I have a data file imported where there is a column for the date. It is custom formatted as [-$409]ddmmmyyyy h:mm:ss:000 so that it takes a number like 41769.68 and has it shown in the cell as 10May2014 16:23:04.883, for instance.
I want to be able to take just the hour and use that for conditional formatting though. For example, if the hour is between 7AM and 11AM, I want another column to say 'morning', or something of that sort. I know I can change the format cells option to just 'h' to get the hour, but using that in another block of code still returns the original 41749.68 number rather than 16, for example.
Is there a way to get just the hour to show in its actual number form rather than the whole date, or if not, is there a way to parse the number 41769.68 to find the hour?
The hour is .68 (the decimal part) *24 (each day is 1 unit to Excel). If you don't want the minutes then either round or truncate (eg with INT). Either way Conditional Formatting will not allow you to format as 'morning'.
You could try:
=HOUR(A1)
With your value in A1, in another cell enter:
=INT(24*(A1-INT(A1)))
will display 16

EXCEL - Substract two 24hr time format cells with seconds and miliseconds

Okay, so I have two cells:
Start End
11:31:37.644 11:31:51.269
I'd like to subtract the two and return the remaining time which should equal something around 14 seconds.
Edit for more information:
My values I'm inputting are like so:
113137.644
113151.269
and I have a custom formatter set to: 00\:00\:00.000 to display what you see at the very top.
It would be better if you could input the values as real time values then you can just use a simple subtraction
=A2-A1
...but with the values as they are you can do a conversion and subtraction all in one using TEXT function, e.g. in A3 use this formula
=TEXT(A2,"00\:00\:00.000")-TEXT(A1,"00\:00\:00.000")
format A3 as [h]:mm:ss.000 to get 0:00:13.625 for your example
Assumes times are on the same "day", if you need to pass midnight you can revise formula to
=MOD(TEXT(A2,"00\:00\:00.000")-TEXT(A1,"00\:00\:00.000"),1)
You need to use the MID function to grab each section of the time, like this:
=MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&"."&MID(A1,8,3)
This will change 113137.644 to 11:31:37.644.
You can then do the math on it like this (all in one cell, but broken up here for readability):
=TEXT(MID(B1,1,2)&":"&MID(B1,3,2)&":"&MID(B1,5,2)&"."&MID(B1,8,3), "hh:mm:ss.000")
-
TEXT(MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&"."&MID(A1,8,3),"hh:mm:ss.000")
That should give you 0.000157697. Change the field's custom format to hh:mm:ss.000 to give you 00:00:13.625.
You can use this formula to convert your values to time
=(LEFT(A1,2)+(MID(A1,3,2)+RIGHT(A1,LEN(A1)-4)/60)/60)/24
You can then subtract and convert back using the following formula
=TEXT(B1,"hhmm")&TEXT(MOD(B1*24*60,1)*60,"00.000")
But it would probably be better for you to actually use proper decimal values in fractions of days or hours rather than this you can't calculate anything with.

Resources