Formula to turn dates into 12 hour categories - excel

I've got some data from a database that lists dates in the following format:
3/2/13 0:09
3/1/13 20:12
3/1/13 3:02
3/1/13 0:45
I need to create a column in my spreadsheet and put them into 12 hour categories, essentially turning it into this:
3/2/13 0:00
3/1/13 12:00
3/1/13 0:00
3/1/13 0:00
If it's between midnight and 12pm, I want it to say midnight, if it's between 12pm and midnight, I want it to say 12pm. I have over 3500 rows of data spanning 2 weeks of dates, so I'm looking for the proper excel formula to make this happen. I've been playing with conditional "If" formulas, but have yet to get it right. Can someone help?!

Excel stores dates & times internally as numbers where 1.0 equals 1d, 0.5 = 12h. Therefore, you can use a simple rounding trick:
=INT(A1*2)/2

Related

Summing time in Excel table gives very large number?

Can anyone help please?
When I sum two time value such as 09:00 and 22:30 I can get a result of 31:30 by formatting the cell using [h]:mm:ss.
However, whenever I try and do this with a subtotal row on an Excel table, it’s gives ridiculously large numbers?! For example, if I do the same as my first example, I get a result of something like 2million?!
Can anyone explain what I’m doing wrong? It works fine outside of the table but I need to use a table since I am populating the values from a PowerAutomate flow.
As above please see my example
Excel uses numbers to represent dates and times. It starts with 0.0 as midnight on Jan 1 1900 , 1.0 is midnight on Jan 2 1900 etc, each whole number is one day since Jan 1 1900 and times are represented using a fractional value. E.g. 0.5 is noon on Jan 1 1900, 2.25 is 6:00:00 am on Jan 3 1900 and so on.
When you sum date-times in Excel , it just sums these numerical values.
In your test case of adding two date-times 9:00am and 22:30 (=10:30pm) and getting 31:30, you are probably summing two fractional values only (e.g. 0.375 + 0.9375 ) to get a whole day and a bit ( = 1.3125) which the format you are using shows you 31:30.
Typically, date-times in Excel are both the whole number and the fraction. For recent dates these numbers can be quite large 44,926.5 is noon on Dec 31st 2022 for example. If you sum even a few of these, as numbers, and try to represent them as dates you will get an absurdly large number.
In order to help you better you will need to tell us the actually numerical value (not the formatted representation) of the underlying cells.

How to calculate the hour between two hour times in Excel?

I have an excel sheet with the following in a row as an example:
'10:00 - 16:00'.. Typically it is HOUR - HOUR2.
I am trying to get the total hours based on this. So 10:00 - 16:00 would be 6 hours. 10:00 to 16:30 will probably be 6.5 hours etc.
Is there an possible way to do this in excel with a formula?
I'm ok with it not doing the overly complex ones (Ones with several hour - hour2 in one column) but it would make it easier if it at least did the ones that are simplistic.
Thanks!
With data in A1, in B1 enter:
=timevalue(RIGHT(A1,5))-timevalue(left(A1,5))
and then apply a time format to B1 to give hours:minutes. To get numeric hours, use:
=24*(TIMEVALUE(RIGHT(A1,5))-TIMEVALUE(LEFT(A1,5)))
You could try:
=TEXT(RIGHT(A1,(LEN(A1)-(FIND("-",A1)+1)))-LEFT(A1,(FIND("-",A1)-2)),"hh:mm:ss")
Results:

Excel - Placing values that fall within a certain time range

I have the following data on duration of particular services.
A B C D
Usage Start (Local time) Start Time Usage Until (Local time) End Time
03.03.2018 10:00 12:00:00 AM 03.03.2018 00:00 1:00:00 AM
03.03.2018 00:00 1:00:00 AM 03.03.2018 00:00 2:00:00 AM
03.03.2018 16:30 1:00:00 AM 03.03.2018 00:00 3:00:00 AM
And I want to count the number of times a timing falls within a certain range(eg. 00:00 - 01:00)
Start End Counts
00:00 01:00 1
01:00 02:00 2
02:00 03:00 1
03:00 04:00
04:00 05:00
05:00 06:00
What formula should I use and how do I apply it?
I have tried this
=COUNTIFS($B$2:$B$566,">="&A2,$D$2:$D$566,"<"&B2)
And this
=SUMPRODUCT(($B$2:$B$566>= A2)*($D$2:$D$566< B2))
But it doesn't account for more than 24 hour duration (Eg.3/3/2018 1:00 PM - 4/3/2018 2:00 PM, 25 hours)
It looks like you're ignoring the time portion in Columns A and C. Assuming your start/end hour bins are in columns F and G, the formula below will give you the number of times that an event passed through your first hour bin (you have to enter it as an array formula--ctrl+shift+enter). Fill down for subsequent hour bins.
=SUM(($B$2:$B$4<F2+TIME(0,30,0))+($D$2:$D$4>F2+TIME(0,30,0))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
This will count an event in an hour bin if the event is active at the half-hour mark.
If the event needs to cover the entire time bin, use this formula (again with ctrl+shift+enter):
=SUM(($B$2:$B$4<=F2)+IF(G2>F2,($D$2:$D$4>=G2))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
Was a bit more complicated than I expected, but I got it to work.
Though before we start, you need to format your table a little. You
can't have date and time in the same cell (as excel has trouble
recognizing storing two formats in 1 cell).
Instead format your table
like so:
Next we should create some hidden rows (technically you can stick what I'm about to do in 1 giant formula, but for sake of clarity I prefer hidden rows)
First we focus on the time difference in hours. Creating the two following columns
Also, make sure, you set the format in these newly added rows to
number. Technically it will work without it, but it will look
confusing to human eye
In the Time defference we use the following formula
=ABS(F2-C2) * 24
In the overnight h column:
=IF(C2>F2, 24-G2, G2) This is utilized that we properly count with transition dates (eg. 23:00 1/1/18 -> 01:00 2/1/18) we don't want to add the extra 24 hours in this case.
That would be the hours fully working, but we also need to ensure the
formula works, when there's more than one night of difference (eg.
1/1/18 -> 3/1/18)
Next, we add these these two rows
In the date difference column, as the column name suggests
=DATEDIF(A2, D2, "d") * 24
Last but not least, the overnight delta is basically the same principle as overnight h, but with dates instead of hours
So now, if we have hidden the rows, added the following formula to result =H2+I2-J2 we get our sought after table:
Which corresponds with the expected result! :)
EDIT: If you don't want to take hours into cosnideration and only count how many times an interval of 24 hours has expired use the following formula
=IF(C2>F2, DATEDIF(A2, D2, "d")-1, DATEDIF(A2, D2, "d"))
(under presumption c2,f2,a2,d2 are in the columns as in my original table i provided)

Set 00:00 as the last timestamp in Excel

I have a feed of 30 minutes meter readings from MySQL to Excel sorted by the first column which is a datetime format, i.e 10-06-2015 00:00:00, 10-06-2015 00:30:00, 10-06-2015 01:00:00 etc.
Because the reading from 00:00:00 each day is actually data from the last 30 minutes of the day, I need the 00:00:00 reading to be the last row for the day rather than the first (as Excel is sorting by time order 00:00 is the default start of each day). Does anyone know how to format this in Excel so that the 10-06-2015 00:00:00 will come after the 10-06-2015 11:30:00 row and not after the 09-06-2015 11:30:00 row?
I don't think you are going to find a way to do that using just formats. Reason being that the format doesn't change the underlying value, which is what excel uses to do the sort in the first place.
I would suggest using a helper column in which you use a formula... maybe something like this:
=IF(A2-ROUNDDOWN(A2,0)=0,A2+0.99999,A2)
Where the first value of your time series is in A1... then copy the formula down and sort on the column B. This worked for me.

If Statement to check time in excel

I need to create an if statement to check time in excel. For instance if time is between
00:00:01 to 06:00:00 I give a value of 1
if time is 06:00:01 to 12:00:00 I give a value of 2
if time is 12:00:01 to 18:00:00 I give a value of 3
and if time is 18:00:01 to 00:00:00 I give a value of 4
Any ideas how I should implement this?
Assuming that the time is in cell A1, you could use:
=CEILING(A1/0.25,1)
It worked on some sample data for me:
12:01:03 3
18:19:00 4
00:00:01 1
The above works because dates are actually numbers in Excel, and 1 unit represents 1 day. So naturally, if you divide 1 day by 4, you get what you are looking for.
You can use Excel Worksheet formula like shown below (it reads the system time using function NOW()):
=IF(HOUR(NOW())>18,4,IF(HOUR(NOW())>12,3,IF(HOUR(NOW())>6,2,1)))
If HOUR is already given in, for e.g., column A1, then use a simplified formula:
=IF(A1>18,4,IF(A1>12,3,IF(A1>6,2,1)))
Try this
=TEXT(IF(INT(TEXT(A1,"[m]"))<=360,1,IF(INT(TEXT(A1,"[m]"))<=720,2,IF(INT(TEXT(A1,"[m]"))<=1080,3,IF(INT(TEXT(A1,"[m]"))<=1440,4,"")))),"#")

Resources