Excel date formatting convert to number - excel

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

Related

Extract the hour from the h" hour(s) and "m" minute(s)" in excel

I have the list of data that showing the Hours and the Minutes that I extract from the system. I need to be extract the hours.
As example below, column B first row, the Hours would be 64 and the minutes would be 46.
But when I used the formula =Hour , its turn up the different value since its actually decimal number.
Cannot use left() , it will give the actual decimal number.
Updated:
We tried the #harun24HR 's but cannot readable the value.
But if you noticed, if i copy and paste the value is different. thats why the search not applicable.
4th Update:
To Solar Mike, I have tried the formula given from the thread the i think the value not readable
It's a time value which Excel stores as calculated value based on 24 hours = 1.
To retrieve the hours only you can use:
=INT(A2*24)
To retrieve the minutes only you can use:
=(A1-(INT(A1*24)/24))*24*60
Your time value is already a number in time format so you just need it to change it to decimal system. Dates and time values are numbers. Even if you see it as 30/09/2019 or 12:00:00, actually, for Excel, both cases are numbers.
First date Excel can recognize properly is 01/01/1900 which integer numeric value is 1. Number 2 would be 02/01/1900 and so on. Actually, today is 44659.
Now, about your data, you posted this screenshoot:
So the value is numeric, not text/string. In Excel, what you see is not always what you have. Probably that column has been formatted using custom mask. My fake data is like this:
The numeric value is 02/01/1900 16:46:36 (or 02/01/1900 4:46:36 PM it depends on your regional settings) but I've applied a custom format like this:
[hh]" hours" mm " minutes"
So what I have is a number but what I see is a text!
We have to work with the number (to be honest, ist's easier to work with numbers), so to extract the total hours, minutes and seconds.
Formula in B1: =INT(A1*24) total hours
Formula in C1: =INT(A1*24*60-B1*60) total minutes
Formula in D1: =A1*24*60*60-B1*60*60-C1*60 total seconds
This should guide you on whatever are you trying to achieve.
From your current sample data you try-
For hour =LEFT(A2,SEARCH(" ",A2)-1)
For minutes =RIGHT(SUBSTITUTE(A2," minutes",""),2)

Formatting Existing Excel Cells to Time Format Without Date

I'm working on an excel 2010 sheet where I mark down the date and time an event happens. The date is in one column, and auto formats to 17-Nov when I would type in 11-17 (I was fine with this). The time is in a separate column.
I am trying to find the average time an event occurred, without regard to the date, so I would use =AVERAGE(C1:C10). However, I only receive a date back (like 17-APR).
I did not format the cells before I began to enter in data, and I would simply type in a 3:27pm event as 1527, and no reformatting would happen.
Now, when I attempt to reformat the column to hhmm, all the numbers entered so far turn to 0000. When I try to edit the 0000, it is formatted as 6/13/1906 12:00:00 AM.
What I want to do is have the time formatted as hhmm and not include a date in the cell, and be able to run formulas on it, such as the average time an even occurred.
Summary:
*Currently time is entered simply as ####. I entered 3:27pm as 1527.
*Trying to reformat the time column results in 0000 in all cells in the column that previously had a ####.
*Modifying the 0000 displays as 6/13/1906 12:00:00 AM
*I want to format the time as hhmm so I can simply type in 2357, and have it display as 2357, but understand I mean 11:57pm, and let me take averages.
*Hell, even being able to enter 1547 and have it auto format to 15:47 or 3:47p would be great.
Thanks for reading my question!
An easy way to apply an autoformat (though Excel won't see it as a true "Time") is to go into Format Cells>Custom> and use ##":"##. This will turn 1245 into 12:45. Mind you, this will be a text string so if you copy it to another cell and then apply a time, it will show as 12:00:00. Excel will also not be able to run formulas on it, but it's a quick and dirty way to make it look pretty.
Another option is to have a formula such as =TIME(LEFT(A1,2),RIGHT(A1,2),) where A1 would be replaced with the cell you are actually referencing. This will convert the number to a time that Excel will recognize as a time allowing you to run other functions on it, but requires another column.
If you are entering the times as 4-digit numbers, you'll need to do a calculation to get the hours and minutes, then use the TIME function to get an actual time:-
=TIME(A1/100,MOD(A1,100),0)
Another way is
=LEFT(A1,2)/24+RIGHT(A1,2)/1440
but then you have to format the result as a time.
Excel sees a number like 1547 as approximately 4 years on from 1st January 1900 if you format it as a date, so it will come out as something like 26/3/1904 in UK format or 3/26/1904 in US-style format.
Note that the time function can only give you values up to 23:59:59 (stored as 0.999988426), but the second method will give you a datetime value with one or more days as the whole number part. This can be useful if you want to do calculations on times spanning more than one day.
The above behaviour is because dates and times are stored as real numbers with the whole number part representing days and the decimal part representing fractions of a day (i.e. times). In spite of misleading information from Microsoft here, dates actually start from 31/12/1899 (written as 0/1/1900) with serial number 0 and increment by 1 per day from then on.

MS-EXCEL: time averages + numbers to time

I am working on a project for my work and I am having an issue trying to take times and averaging them out. I am getting a #DIV/0! When I convert the cells to XX:XX.
Below are screen shots of the same data and function. The top is with regular numbers the bottom is where I formatted all cells to display in time XX:XX.
Numbers (works fine)
= AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Time (XX:XX) however I get the #DIV/0!. The AVERAGE Function I am using looks like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Also, if possible, could I enter the data in regular numbers (not time) then have it display in average time (hours:min) on the right?.
Thank you.
When working in Excel with dates and times always leave the value as a number and apply formatting. where you have tried to enter a time in hh:mm, you need to show the hours even if they are blank, or the value of that cell becomes a string. But you can't average a string.
These are valid entries 00:23 or 0:23
:23 is not valid time, so is treated as a string
Valid times are stored as a number where 24 hours = 1.
Times are stored as a fraction for example 0:45 = 0.031250000
To fix it, add in the missing leading zeros, or if you have explicitly entered text strings: type a 1 in any cell and copy it, then select all of your time cells and do paste special multiply. That will convert them back to numbers and your average should work. Then apply your custom formatting of required .
I would suggest that users enter the time in minutes eg 17, 23, 92 and you average these, but for the conversion I suggest that you use a formula like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)/(24*60)
This will convert the average time in minutes, into a fraction of a day.
You can then put custom formatting onto the cell to change the format to hh:mm

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.

Excel 2007: How to display mm:ss format not as a DateTime (e.g. 73:07)?

I need to create and Excel table that computes daily training times. each row has the following fields: Date, Distance, Time and Minutes/Km. My main problem is that I want to display the Time in format of mm:ss. For example: 24 min and 3 sec should be 24:03, but "Excel" turns it to 00:03:00 (3 min after midnight). I've tried setting up "special formatting" but still "Excel insists" on formatting the hours. More over, training may exceed 60 minutes and I still want it only as mm:ss
My second question is after I'm done with the formatting issue, what is the simple way to compute Time/Distance?
enter the values as 0:mm:ss and format as [m]:ss
as this is now in the mins & seconds, simple arithmetic will allow you to calculate your statistics
Excel shows 24:03 as 3 minutes when you format it as time, because 24:03 is the same as 12:03 AM (in military time).
Use General Format to Add Times
Instead of trying to format as Time, use the General Format and the following formula:
=number of minutes + (number of seconds / 60)
Ex: for 24 minutes and 3 seconds:
=24+3/60
This will give you a value of 24.05.
Do this for each time period. Let's say you enter this formula in cells A1 and A2. Then, to get the total sum of elapsed time, use this formula in cell A3:
=INT(A1+A2)+MOD(A1+A2,1)
Convert back to minutes and seconds
If you put =24+3/60 into each cell, you will have a value of 48.1 in cell A3.
Now you need to convert this back to minutes and seconds. Use the following formula in cell A4:
=MOD(A3,1)*60
This takes the decimal portion and multiples it by 60. Remember, we divided by 60 in the beginning, so to convert it back to seconds we need to multiply.
You could have also done this separately, i.e. in cell A3 use this formula:
=INT(A1+A2)
and this formula in cell A4:
=MOD(A1+A2,1)*60
Here's a screenshot showing the final formulas:
To make life easier when entering multiple dates/times it is possible to use a custom format to remove the need to enter the colon, and the leading "hour" 0. This however requires a second field for the numerical date to be stored, as the displayed date from the custom format is in base 10.
Displaying a number as a time (no need to enter colons, but no time conversion)
For displaying the times on the sheet, and for entering them without having to type the colon set the cell format to custom and use:
0/:00
Then enter your time. For example, if you wanted to enter 62:30, then you would simply type 6230 and your custom format would visually insert a colon 2 decimal points from the right.
If you only need to display the times, stop here.
Converting number to time
If you need to be able to calculate with the times, you will need to convert them from base 10 into the time format.
This can be done with the following formula (change A2 to the relevant cell reference):
=TIME(0,TRUNC(A2/100),MOD(A2,100))
=TIME starts the number to time conversion
We don't need hours, so enter 0, at the beginning of the formula, as the format is always hh,mm,ss (to display hours and minutes instead of minutes and seconds, place the 0 at the end of the formula).
For the minutes, TRUNC(A2/100), discards the rightmost 2 digits.
For the seconds, MOD(A2,100) keeps the rightmost 2 digits and discards everything to the left.
The above formula was found and adapted from this article:
PC Mag.com - Easy Date and Time Entry in Excel
Alternatively, you could skip the 0/:00 custom formatting, and just enter your time in a cell to be referenced of the edge of the visible workspace or on another sheet as you would for the custom formatting (ie: 6230 for 62:30)
Then change the display format of the cells with the formula to [m]:ss as #Sean Chessire suggested.
Here is a screen shot to show what I mean.
If you are using hand inputted data, you can enter your data as mm:ss,0 or mm:ss.0 depending on your language/region selection instead of 00:mm:ss.
You need to specify your cell format as [m]:ss if you like to see all minutes seconds format instead of hours minutes seconds format.
as text:
=CONCATENATE(TEXT(cell;"d");" days ";TEXT(cell;"t");" hours ";MID(TEXT(cell;"hh:mm:ss");4;2);" minutes ";TEXT(cell;"s");" seconds")
5.In the Format Cells box, click Custom in the Category list.
6.In the Type box, at the top of the list of formats, type [h]:mm;# and then click OK. (That’s a colon after [h], and a semicolon after mm.)
YOu can then add hours. The format will be in the Type list the next time you need it.
From MS, works well.
http://office.microsoft.com/en-us/excel-help/add-or-subtract-time-HA102809662.aspx
One convenient trick to entering elapsed times into Excel is to have two zeros and a colon before the number of minutes, details follow. For copy and paste operations into Excel without have to worry about formatting at all one can use the format 00:XX:XX where XX are two digits totaling < 60. In that case, Excel will echo 0:XX:XX in the cell contents displayed and store the data as 12:XX:XX AM. If one pastes data in a 00:XXX:XX format into Excel, or 00:XX:XX where either XX > 59 this will be converted into a fraction of a day.
For example, 00:121:12 becomes 0.0841666666666667, which if multiplied by the number of seconds in a day, 86,400, becomes 7272 s. Next, 00:21:12 would by default show 0:21:12 stored as 12:21:12 AM. Finally, 00:21:60 becomes 0.0152777777777778, also a fraction of a day.
This suggestion is made merely to avoid having to worry about specific formatting in Excel, and letting the program worry about it. Note, for Excel data internally formatted as 12:XX:XX AM one can only use certain Excel commands, for example, one can take an average. However, subtraction will only work when the result is a positive number. Such that converting times into seconds, fractions of a day, or other real number is suggested for access to more complete arithmetic operation coverage.
For example, if one has a column of mixed time formats, or times that are negative and will not display, if one changes the number formatting to General, all the times will be converted to fractions of a day.

Resources