How can I convert time into decimal in excel? - excel

I was using a formula for converting hours greater than 24 hours but that formula gives an error when it comes to thousands of hours.
I want to convert 283398:02:08 into decimal, but every time I try it gives an error.

In Excel, the largest amount of time that can be entered manually is 9999:59:59.
If you are entering time manually and it is greater than that, it will be converted to a text string.
To convert the text string to decimal hours, you need to use text manipulation functions to split the string (by the colon) and multiply the hours*1, minutes*1/60, seconds *1/60/60
So, if you have Excel 2013+ with the FILTERXML function, you can use:
=SUMPRODUCT(FILTERXML("<t><s>" & SUBSTITUTE(A1,":","</s><s>")&"</s></t>","//s"),{1;0.0166666667;0.00027777778})
If the time is a number, and not a string, then just:
=A1*24
and format as a decimal number

Related

How to convert UTC to datetime in Excel

I am trying to convert UTC to datetime in EXCEL SHEET.
Below is the input
2020-04-10T22:15:40.5577209Z
So far to convert I have put below formula
=(SUBSTITUTE(A2,"T"," "))
This gives me output as
2020-04-10 22:15:40.5577209Z
Now I need to trim the .5577209Z part.
Final output should be
2020-04-10 22:15:40
Can someone help me with this?
The result you want would be produced with a formula like this one. (The original string is in A2)
=DATEVALUE(LEFT((SUBSTITUTE(A2,"T"," ")),18))+ TIMEVALUE(LEFT((SUBSTITUTE(A2,"T"," ")),18))
The formula takes the first 18 characters of the received string. If you are sure that there are no letters in the next couple of digits you could extend this to 20 or more and get a better rounding of the seconds.
Another approach would be to work around the offending "T".
=DATEVALUE(LEFT(A2,10))+TIMEVALUE(MID(A2,12,8))
Again the final 8 in the formula could be extended for better rounding of seconds. Or, if it's always a "Z" it could simply be removed like you already removed the "T".
Either solution gives you a true Date/Time value - a 5-digit number with lots of decimals. This you convert into a legible date by means of the cell format. Apply a custom format like yyyy-mm-dd hh:mm:ss

Convert Text to Time with milliseconds

When I paste a time with milliseconds like this 21:34:58.342 into excel, it does not get converted into time format and is stored as text instead. I've tried converting it manually by means of =--TEXT(A1;"hh:mm:ss.000") but it produces #VALUE! error.
How do I convert time with milliseconds text to time format?
Update
If I paste 21:34:58 the value is converted into Time correctly. If I apply h:mm:ss.000 format to the resulting cell the value is displayed as 21:34:58.000. But if I edit the cell and add a millisecond to the value 21:34:58.001 it becomes Text.
Most likely, your system (see Windows Regional Settings) decimal separator is not a dot. You need to use your system decimal separator when you enter the millisecond value. Most likely, that is a comma. You may need to use your system decimal separator in your format string also.

Output time using xlswrite

I am attempting to create a timestamp (date, or date and time) using either
t=now;
or
t=date;
and when it outputs using xlswrite, the date or time and date become spread throughout a half dozen cells. I've tried converting into arrays and vectors and it has same output.
Thank you
if you only give a string to xlswrite, MATLAB will put each char in one cell. To get an entire string into one Excel cell you have to make a cell out of it in matlab. 'date' returns a string with todays date, so that part is easy
xlswrite('test',date); % one char in each
xlswrite('test2',{date}); % entire date in [1,1]
'now' on the other hand is the number of days (float point for hours and so on) since 0000-01-01 00:00. Writeing this is a little bit tricky since MATLAB uses 0000-01-01 as reference while Excel takes 1900-01-01. so you have to not only put now in a cell but also make a string out of it before passing it to Excel.
If you dont you either end up with a date in the sweet year 3916 or there will be just the MATLAB datenum as double which is a number around 730000. Which of the 2 happens is dependent on your MATLAB and Excel Version and on the fact what else your write in that .xls. but as they are equally unwanted always go for datestr:
mycell=cell(2,1)
mycell(1)={now}
mycell(2)={datestr(now)}
xlswrite('test3',mycell)

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

how to prevent excel 2010 from converting times to decimals automatically when cell is pasted

As you might have come accross, MS Excel tends to convert times to decimal values. I do want it to convert the values automatically because I need the time value. Suppose I have following data:
Departure | Time
Istanbul 06:45
Ankara 01:30
I am using Concatenate function to create a desired string as Istanbul: 08:00 and Ankara: 18:30. However, when I use the formula, Excel converts hours to decimals and I get Istanbul: 0.28125 and Ankara: 0.0625. I do not want it to convert. How can I do this?
ps: This also happens when I copy time values from Excel to Notepad++. Moreover, when I import time values into PostgreSQL through add-in, I still get decimal values in the columns
You want to use the TEXT function to convert the time into the text format that you require. Something like this:
=CONCATENATE("Istanbul: ", TEXT(A1,"hh:mm"), " and Ankara: "18:30, TEXT(A2,"hh:mm"))

Resources