Round time to nearest 10 milliseconds - excel

I have some time data that, without VBA, I need to round to the nearest 10 milliseconds. For example:
input: 01:02:03.017 output: 01:02:03.020
input: 03:12:44.123 output: 03:12:44.120
Current approach is to convert to an integer number of milliseconds; round that to the nearest 10; finally convert back to time:
=ROUND(A1*86400000,10)/86400000
I must be making a really stupid error, just don't see it.
EDIT:
The formula is returning the same value as the input?!?

Change the 10 to 0
By multiplying the value you want the round to the nearest integer, then divide again. By using 10 you are rounding to the 10th decimal place after creating a integer time.
=ROUND(A1*86400000,0)/86400000

Assuming your time data is in column A:
=TEXT(A1,"hh:mm:ss.00")+0
Change the number format with TEXT, then add the ending 0 with +0

Related

how to get zulu time difference seconds/milliseconds in excel

The excel column contains Zulu Timzezones How to calculate the difference between two dates in seconds.milliseconds
From Time 2022-04-25T04:16:57.823121842Z
To Time
2022-04-25T04:16:58.173194593Z
2022-04-25T04:16:58.089133751Z
2022-04-25T04:16:58.462278784Z
2022-04-25T04:16:57.829376293Z
2022-04-25T04:16:57.961790312Z
2022-04-25T04:16:58.445884586Z
2022-04-25T04:16:57.830806273Z
2022-04-25T04:16:58.067723338Z
2022-04-25T04:16:58.470913276Z
2022-04-25T04:16:57.838787068Z
When I Try to Do something like =B13-B14
Error
Function MINUS parameter 1 expects number values. But '2022-04-25T04:35:59.092943356Z' is a text and cannot be coerced to a number.
Converted to Number format
REVISED: I forgot to convert the milliseconds
You can convert the date strings into time values by breaking them into parts:
=DATEVALUE(LEFT(A2,10)) + TIMEVALUE( MID(A2,12,8) ) --MID(A2,20,10)/24/60/60
Where A2 is the date string.
This assumes that they have the exact structure that you have shown and fully padded with zeros. If that is not the case, for example the milliseconds could be .095Z, then you can mod this to:
=DATEVALUE(LEFT(A2,10)) + TIMEVALUE( MID(A2,12,8) ) --MID(SUBSTITUTE(A2,"Z",""),20,999)/24/60/60
to be safe.

Error while Multiplying a u64 to u128 in Rust?

I want to multiply a u128 number with a u64 number. u64 will always be less than or equal to one. Amount is always greater than 1000000(1 million)
fn testing(amount:u128, starting_time:u64, ending_time:u64, duration:u64){
return amount*((ending_time - starting_time:u64)/duration)
}
Even if the number should return something like 500,000 it always returns zero unless the ((ending_time - starting_time:u64)/duration) equals 1 then the return value always amounts.
I want to give less weightage to someone if they enter the last to the lottery. Both starting and ending times are u64 because they are in UNIX timestamps.
Example: Let's say Alice entered the lottery at time 0. Same time the lottery was started. So Alice would get full weightage for the amount she deposited let's say she deposited 30000 so she will get 30000 tickets.
Bob entered the lottery halfway through the lottery means that whatever he deposits he will get half the weightage of the deposited amount. If he deposits 30000 he will get 15000 tickets.
The best solution I found is:
(amount/1000000) * (( ((end_time - start_time)*1000000 )/duration ) as u128)
I see 2 problems with your code:
You are trying to subtract 2 timestamps, but is that going to leave you with a timestamp? or a number? and if it is the number, is that in seconds or milliseconds or what? and does duration also represent seconds or milliseconds or is it another timestamp?
If all that code still makes sense, then you have a second problem:
Your expression: ending_time - starting_time)/duration, presumably you are expecting it to be a fraction between 0 & 1, right? well if all your variables are ints, then your result is going to be an int, which means guess what? no fraction.
You need to cast all that stuff to floats, or multiply the amount first so you don't have to worry about the fraction. Maybe try this:
return amount*(ending_time - starting_time)/duration;

Converting number to time in excel - variable number of digits

I have a report which is downloaded from a Warehouse Management System.
On this report there is a time column which unfortunately puts the time into a string of numbers that can be anywhere from 5-8 digits long.
I.e.
22434900 = 22:43:49:00 with 22 being the hour, 43 the minutes, 49 the seconds.
2480000 = 02:48:00:00 with 2 being the hour, 48 the minutes etc.
54300 = 00:05:43:00
The 00 on the end (milliseconds) doe not change in each number so is quite irrelevant.
Is there an easy way to format the text in these cells so it shows as a time as oppose to a number?
Thanks in advance.
I know I'm late, but here's an alternate solution:
=TIMEVALUE(TEXT(A1/100,"00\:00\:00.00"))
Again, as mentioned in Jerry's answer, you'll need to use cell formatting of hh:mm:ss.00
You can use TIME with some math functions:
=TIME(INT(A1/1000000),MOD(INT(A1/10000),100),MOD(A1/100,100))
TIME takes 3 parameters: hours, minutes and seconds.
To get the hours, I'm dividing by 1000000, then INT rounds it down to the closest integer.
To get the minutes, I'm first dividing by 10000, but there is still the hours in that result. So I use MOD (which gives the remainder when a number is divided by another number). In the first example, the division gives 2243, and the remainder when dividing this by 100 is 43, which is the number of minutes I'm looking for.
To get the seconds, I divide the number by 100 and similar to the minutes, I use MOD to remove the minutes and hours parts. I am not using INT here in case there are milliseconds, which will be kept using this formula.
Also note that I am using the formatting hh:mm:ss.00, because excel complains if I try using hh:mm:ss:00.
For your Warehouse Management System query you may want to try something like this:
• Taking the 6 digit numeric time and making this into a string that the time function can handle
• Using the digits function to avoid issues with varying lengths of data (i.e. 64512 vs 1113012)
• Use the function Time over this string to return the value (this way we can add hours or minutes as the example below)
Here is an example to experiment with this and :
select MyTimeField
, time(int(MyTimeField/10000) || ':' ||
substring(digits(MyTimeField),3,2) || ':' ||
substring(digits(MyTimeField),5,2))
from MyTable where MyCompany = 1 and MyInvoiceDate = Current_date

Converting large time format to decimal in excel

I'm trying to convert a large time value in excel to a decimal number for hours.
I currently have a column adding up "Ready time" for a call centre which is 3545:20:02 as a SUM. I now want that to show me the same hours in a decimal format e.g. 3545.333 as it's used in another calculation.
For reference, when I convert the above time to a General excel value, it is 147.7222454.
The formula I've been using is: =IFERROR((DAY(M54)*24) + HOUR(M54) + (MINUTE(M54)/60),0) and has been working fine for smaller time values.
Thanks in advance!
Excel counts in days (1 day = 1) so for hours you just multiply by 24, i.e.
=M54*24
format result cell as number with required number of decimals
[the reason your current formula fails is because of DAY function - DAY is day of the month so it fails for you when the time value is >= 32*24 = 768 hours]

Truncate to the nearest thousandths and ignore the remainder of the value

Can MS Excel do rounding but only up to the nearest thousandths place and ignore the rest of the decimals in a formula? I've tried value, fixed, round and none of these do what I need.
Let's say I have 100 square feet of space and I pay $1.00566399 per sq foot, I need the formula to round only up to the 5 and ignore the rest of the numbers because when you speak on longer terms it makes a difference in rate.
So I should be multiplying 100sf by $1.01 = $101.00 and not get 100sf * 1.00566399 = $101.57
=trunc(A1,5)
If you want to round up, maybe something like
=trunc((A1*10000+1)/10000,5)
Use the TRUNC($cellRef or number, Decimal places) function. It reduces the number of decimal places WITHOUT rounding, then do your math.
So for example:
=TRUNC(1.00566399,3)
=A1*ROUNDUP(B1,2)
Where A1 contains the number of square feet and B1 contains the price per square foot in it's original long decimal form.

Resources