Convert date & time in Excel, to time only, and round to nearest 30 minutes - excel

I need a formula to convert excel date & time to time only and nearest 30 minutes. Example 1/5/2017 4:38:29 PM convert to 1630
A1 B1
1/5/2017 4:38:29 PM 1630
1/5/2017 5:03:40 PM 1700
1/5/2017 4:39:27 PM 1630
I tried if function & vlookup with
=MROUND((TEXT(A1,"hhmm")),1/48)
but I get 0:00 answer, and also
=MOD(Y5,"0:30")
but I get a 0 answer.

It looks like you were almost there. You need MOD to get the decimal portion of a datetime (i.e. the time) then MROUND to the nearest half-hour.
=MROUND(MOD(A1, 1),TIME(0,30,0))
FLOOR and CEILING operate the same as MROUND in case you require the lower or higher half-hour.
You may need to format the cell for the desired time format mask.

Assuming data starts in A1, copy the following down to suit:
=HOUR(A1)&IF(MINUTE(A1)>29,30,"00")

Related

Excel Powerpivot Dax(not native excel)- convert time to decimal hours

I have a list of times:
8:30PM
8:15PM
7:20PM
How can I convert these to decimal hours in Powerpivot (DAX)?
for example:
8.5
8.25
7.33
Use this formula DecimalNumber = Sheet1[DATE]*24, or simply multiply your time with 24. 8:30PM can never evaluate to 8:30 since it is PM, so it's actually 20:50. If you want it to be 8:50 instead, then subtract 12 from formula.

How does Excel convert 12 hour time (text values) into decimal numbers?

I'm trying to find the manual function on how Excel converts am/pm time (text) values into numeric decimals (using the Format menu > Number while selecting my 12 hour time column).
For example, how does 12:30:00 PM turn into 0.52083?
Thank you.
Date and time can be handled in many ways. The time representation you are observing in Excel is based on 1 day = 24 hours = 1.0. So 12:00 pm should be exactly 0.5, while 12:30:00 pm would be a bit (30/(24*60) = 1/48 = 0.0208333) above.
Btw. 12/24 hour is just a region specific presentation issue. Internally this doesn't affect the actual date and time values.

Average column by specific datetime associated values

I have one column with the time in format "dd/mm/yyyy hh:mm" and another with the temperature for that time point. I am looking to calculate the average temperature of the day and night of each month separately. I.e. average all temperatures between 06:00 and 18:00 in May and all temperature between 18:00 and 06:00 in May and then the same for March and so on.
Time Celsius(C)
06/05/2016 10:49 28
06/05/2016 11:49 29
06/05/2016 12:49 31
06/05/2016 13:49 27.5
06/05/2016 14:49 24
06/05/2016 15:49 25
06/05/2016 16:49 24.5
06/05/2016 17:49 23.5
06/05/2016 18:49 23
06/05/2016 19:49 22.5
06/05/2016 20:49 22.5
I am currently using the following formula:
=AVERAGEIFS(C2:C3643,B2:B3643,">=01/05/2016",B2:B3643,"<=31/05/2016",B2:B3643,">=01/05/2016 06:00",B2:B3643,"<=31/05/2016 18:00")
To try and calculate an average if the date is within May and during the day - however it doesn't appear to be working and when I change the hour periods it still spits out the same number (which is the average for the month).
You can use a long SUMPRODUCT Formula:
For the 600 to 1800 in May:
=SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*(MOD($A$2:$A$12,1)>=TIME(6,0,0))*(MOD($A$2:$A$12,1)<=TIME(18,0,0))*B2:B12)/SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*(MOD($A$2:$A$12,1)>=TIME(6,0,0))*(MOD($A$2:$A$12,1)<=TIME(18,0,0)))
You can always replace all the DATE() and TIME() parts with cell references instead of hard coding them.
To get the between 1800 and 600 we need to shift it to an OR with + between the Time Boolean instead of *:
=SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*((MOD($A$2:$A$12,1)<=TIME(6,0,0))+(MOD($A$2:$A$12,1)>=TIME(18,0,0)))*B2:B12)/SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*((MOD($A$2:$A$12,1)<=TIME(6,0,0))+(MOD($A$2:$A$12,1)>=TIME(18,0,0))))
This relies on you creating a table of months and time ranges like below:
Enter this formula in E2 and drag around as needed. It's an array formula, so must be entered with Ctrl-Shift-Enter:
=AVERAGE(IF(
((MONTH($A$2:$A$101)=MONTH(E$1&1))*
((MOD(HOUR($A$2:$A$101)-LEFT($D2,2),24))>=0)*
((MOD(HOUR($A$2:$A$101)-LEFT($D2,2),24))<12)),
$B$2:$B$101))
Notes:
The MONTH(E$1&1) part lets you get a month number from text like
"Jan"
I used MOD and subtraction of the left part of the time range to get
the target hour in a range from 0 to 23. This made it possible to filter on values between 1 and 11.
If Barry Houdini were still around he could do it in half the space, I'm sure.
While working with datetime and when the actual day is reckoned beyond midnight like in 18 hrs to 6 hrs the next day, I find it useful to offset the time back and do the calculations.
6:00 to 18:00 =AVERAGE(IF((MONTH($A$2:$A$12-0.25)=D2)*(MOD($A$2:$A$12-0.25,1)<0.5),$B$2:$B$12,""))
18:00 to 6:00 =AVERAGE(IF((MONTH($A$2:$A$12-0.25)=D2)*(MOD($A$2:$A$12-0.25,1)>=0.5),$B$2:$B$12,""))
These are array formulas entered with Ctrl-Shift-Enter.
Here I am offsetting time by 0.25 days which is 6 hours.

Adding/Subtracting Whole numbers from Time

I have tried every which way to format cells to subtract the result from time for instance the formula in the cell = 11(this is 11 minutes) I want to take that result minus 8:00:00 to give me 7:49:00 but it doesn't work the result is ####### no matter how big I make the cell. And if I format the cells with the formula to custom [m]:ss then the value changes.
Sample of the Worksheet:
I want Y2 = X3-W3 in a time format.
So, if A1=11
Then in some other cell, (B1 in this example): =TIME(,A1,)
Then subtract from the cell with 8:00:00. (If it's C1...:)
=C1-B1
That will give you the time you want.
Info: The main thing is that you have to tell Excel that your cell with the "11" in it, is minutes. By using the =TIME(,A1,) you will get the value of: 12:11 am. (If you keep it in Date format.) 12:11 am could also be viewed as: 0 Hours, 11 minutes, 0 seconds. And now that it knows, you should be able to subtract.
Try this:
=TIME(HOUR(X3),MINUTE(X3)-W3,SECOND(X3))
The ######### is because you have a negative time. Becuase Excel reads time as decimals of 24 hours, 8:00:00 is .3333 and if you subtract 11 from that you get -10.6666 and date/time can not be negative.

how to convert decimal time to hh:mm time format in excel

I have looked at all the options I can find on this forum, but I am unable to solve my problem. this may very well be because I only have basic excel skills. simple question..how do I convert a decimal time ie 9.25 into hh:mm format ie 09:25 ? I need to do this as I am using existing data that requires rounding to 15 mins + 2mins and I can only do this in hh:mm format. Many thanks
Assuming your value is in A1...
Get the hours
=FLOOR(A1, 1)
Get the decimal portion
=A1 - FLOOR(A1, 1)
Convert this decimal to minutes (0.25->25):
=(A1 - FLOOR(A1, 1)) * 100
Bring the whole lot together:
=TIME(Floor(A1, 1), (A1 - FLOOR(A1, 1)) * 100, 0)
Result: 9:25 AM
If it's a true decimal time then 9.25 hours should convert to 9:15. If that's the case you can just divide by 24, e.g. 9.25 in A1 then in B1
=A1/24
format B1 as [h]:mm and you'll get 9:15
....and if you really do want 9:25 as the answer you could try this formula
=TEXT(A1*100,"00\:00")+0
format result cell as [h]:mm- that will work even for values > 24
If you want you can do your conversion and rounding in one go, e.g. to round to the nearest 15 minutes the first formula becomes:
=MROUND(A1/24,"0:15")
Let's suppose you have 9.25 in cell A1. First you need to extract the integer part (9). Let's put this in B1:
=FLOOR(A1)
Now we must get the decimal part:
=A1-B1
And convert it into the ratio-to-60, so let's have this in C1:
=(A1-B1)/0.6
This way, 0.25 becomes 0.4166... (Of course 0.30 would become 0.50).
Finally, add both values and divide by 24. In Excel, dates/times are stores as decimal numbers in which 1 = 24 hours. So let's place this in D1:
=(B1+C1)/24
The result is 0.392... And if you give that cell a time format, you will see 09:25.
So, now let's put all together in one cell:
=(FLOOR(A1)+(A1-FLOOR(A1))/0.6)/24
Don't forget to format the cell as time (custom format "hh:mm", for example).

Resources