I'm struggling to make a formula work in excel.
My case : I have data in m/d/yyyy h:mm AM/PM format on E col.
I have data that goes to the next day post midnight. I'm looking to create another column lets say F where I want to check for data between time 5:30pm to next day 5:30am and return date in m/d/yyyy(col F)
Example :
Let's say a job request came in at 3/21/2021 4:30am, I want it to return 3/20/2021 on col F (previous date)
This is required due to different timezone and unfortunately the timezone cannot be altered on the data.
If it's really true that your data are in "m/d/yyyy hh:mm PM format" then this formula will deduct 8 hours from the value found in E4 and return a true date.
=DATE(RIGHT(LEFT(E4,FIND(" ",E4)-1),4),LEFT(E4,FIND("/",E4)-1),MID(E4,FIND("/",E4)+1,1+ISERROR(FIND("/",MID(E4,LEFT(E4,FIND("/",E4)-1),2)))))+TIMEVALUE(MID(E4,10,10))-(8/24)
A "True" date is a number which takes its display format from the cell format you set, meaning the "data" are different from the display. A "Fake" date (my expression) is a text string that looks like a date but is unsuitable for calculations because it's not a number. The "data" underlying a fake date are identical to the display. My above formula spends 95% of its effort on converting the fake date into a true one and is likely to earn your comment that it "doesn't work" because it returns a number. If so, don't comment. Set the cell format to the kind of display you want.
Of course, if E4 has a true date the effort can be reduced and the formula you seek would be simply
=E4-(8/24)
This is because in Excel dates one day has a value of 1. Therefore 1 hour = 1/24 and 8 hours = 1/24*8 or 8/24. Change the number of hours as desired, add or subtract them from the original as needed.
BTW, if your original data are really text (fake dates) do consider converting them to true dates using the 95% part of my first formula and then processing them as true dates. As you see, there is no advantage in keeping fakes around.
Related
I have got a start date and end date in this custom format
dd.mm.yyyy hh:mm in excel cells.
What i need is to fill specific row with dates incremented by half hour from start date to end date using VBA code. And i havent got any idea how to do this.
On web there are some examples with similar problems but with only months or only hours and those are dates format not custom.
You can do this with a simple formula.
Write your start date into cell A1
In A2 write =A1+(1/48)
Copy formula from A2 down
done.
How does this work?
Excel dates are represented as count of days since 1900. That means 1900-01-01 is the first day and represented by 1. All other dates are just the count of days since then. 1 represents one day. So since 1 day has 24 hours 1/48 represents half an hour.
The number format dd.mm.yyyy hh:mm how Excel shows the date is not relevant, because Excel only saves the value (amount of days since 1900) in the cell value.
So if you type the date of today into a cell 2018-10-11 Excel actually saves 43384 in the cell value (today it is 43384ᵗʰ day since 1900-01-01).
One option is to find the interval between start and stop point. Remember that excel dates that are actually dates and not strings are actually integers. The second thing to remember is time is the decimal part which represent fraction of a day. Test if your date (assuming it's in A1) is an actual date or a string with
=ISNUMBER(A1)
If that comes back TRUE you do not need to worry about converting your date. If it comes back FALSE, its actually a string and will need to be converted for excel to work with it.
Divide this interval by 30 minutes, or 30/60/24 to and add 1. This will tell you how many iteration you will need which you can put into a For loop
Start_Number = Range("A1")
End_number = Range(("A2")
Stamp = Start_Number
Interval_number = End_Number - Start_Number
Counter = integer of (Interval_number / (30/60/24))
For x = 1 to counter
write Stamp to cell
Stamp = Stamp + 30/60/24
Next x
Allternatively you could set up a while loop.
Do While datetime < Stop_Point
Write datetime to cell
Datetime=datetime + 30/60/24
Loop
Please note, not actual code but giving idea where OP had no idea where to start.
I have a spreadsheet that lists the date and time of an event in the same cell (mm/dd/yy h:mm). I need to find a way to count how many events took place between a certain time range in a Hourly Basis.
I could sum if the cell contains dates only however the cell contains with date which i am unable to get the values.
Basically, all datas are in cell A, so i need to count how many events happened at 6am, 7am , and so on... as on hourly basis.
Your column A looks like properly formatted date & time value, so its manipulation is easy. If it's not (ie, not date but text) you should first convert it to date value.
=DATE(MID(A2,7,4), MID(A2,4,2), LEFT(A2,2)) + TIME(MID(A2,12,2), MID(A2,15,2), RIGHT(A2,2))
Say this was C2. Now that column C is date & time, set $D$2 to date to query(ex 2017-03-26), E2 to start time(ex 6:00), and F2 to end time(ex 7:00), then you can count events from 6:00 to 7:00 like this:
=COUNTIFS(C:C,">="&($D$2+E2), C:C,"<"&($D$2+F2))
Sample file is here and its screenshot is below.
If the times spanned different dates and you still wanted to see how many events happened in a particular hour of the day, you would need an array-type formula, e.g. if the start time in hours (entered as a normal number) is in C2
=SUMPRODUCT(--(HOUR($A$2:$A$10)=C2))
or if the start hour is entered as a time
=SUMPRODUCT(--(HOUR($A$2:$A$10)=HOUR(C2)))
I am trying to take the values of time passed (formatted HH:MM:SS) and convert it to just minutes.
The issue I am having is that when I try and get the value of the time-value cell, it converts it to some odd value.
Example:
Wrong Value (what Excel gives me now, in worksheet):
34:32:12 = 1.43902777777778
Right Value (what Excel should give me):
34:32:12 = 2072.2
Calcualted:
34*60 + 32 + 12/60
Assuming your source value is in cell A1, here is all you need:
=N(A1*1440)
This method does not require a reformatting of the output cell.
How does it work?
Dates and times are stored in Excel as a combined number... where the integer portion represents the number of days since December 31, 1899 (although the year that Excel calculates from can be changed to 1904 in the Excel Options, but that is immaterial).
The decimal portion of the stored number represents the time component to associate with the date.
Your value of 1.43902777777778 is correct. It states that the ~34.5 hours represents ~1.44 days.
Since you are interested in minutes, we convert that days figure to minutes by multiplying by 1440 as there are 1440 minutes in a day.
The N() function that wraps that calculation ensures that the displayed output is treated as numeric by Excel. Otherwise the output cell would adopt the date-formatting of A1.
Either format the cell as [m] to see 2072, or multiply by 1440 (the number of minutes in a day) and format as 0.0 to see 2072.2
I have an amount of data sort per date (e.g : 2013-12-12 10:51:51.000) and I want to display that data on a day-long plot : The plot will show the sum values or the % for each hours of the day from 0:00 to 23:59.
My problem is I don't know how to sort data "modulus day", since the date is store in one cell and so day and hours are not separates.
Thank you for your help
The Date in Excel cell is stored as a decimal, where integer part corresponds to Date and decimal to time after midnight, so for example 6/30/2014 9:00 is essentially equal 41820.38. Thus, the sorting should work perfectly fine: it will be using underlying numeric representation of Date and Time as explained above.
Pertinent to your further requirement, i.e. to sort only on time part (decimal) ignoring Date (integer) the solution might be as following: Assuming Date is stored in Column A (cell A1 for example), put a formula in Column B (cell B1)
=A1-INT(A1)
and extend it to entire range, then sort on Column B. Optionally, for your convenience, you can convert the cell format in Column B to Number (to view just decimal part).
Rgds,
Is there a way to convert the below Excel formula to a query/criterion in Access?
L2 = Date
J2 = Another Date
Z1 = Todays Date
I think it is calculating the number of days in between two dates but not sure how to do this in an Access query.
IF((AND((L2<1),(J2>1))),(NETWORKDAYS(J2,$Z$1)-1),0)
As you may by now have gathered, the question does not really make sense. NETWORKDAYS does indeed calculate the number of “whole working days excluding weekends and any dates identified in holidays” between two dates (here whatever date is in J2 and whatever is ‘Today’/Z1) and IF makes that calculation contingent upon the result of the AND function being TRUE. The AND function results in TRUE provided both the ‘date’ in L2 is before 1/1/1900 and the date in J2 is after 1/1/1900 (because to Excel 1/1/1900 is Day 1 where dates are concerned [unless one opts for the 1904 date system]).
But Excel does not recognise a date before Day 1, whether a negative number or a decimal number. For example Day 1.5 is noon on 1/1/1900 whereas in the same format Day 0.5 shows as 0/1/1900.
So in essence, L2 is not a date of any real use to the formula, hence I believe why no answer yet to your question. But this is too long to fit in a comment hence my answer: “No.”!
Set a reference to Excel.
Option Compare Database
Private Sub Command2_Click()
MsgBox GetNetWorkDays(#1/29/2017#, #2/8/2017#)
End Sub
Function GetNetWorkDays(startDate As Date, endDate As Date) As Integer
GetNetWorkDays = WorksheetFunction.NETWORKDAYS(startDate, endDate)
End Function
Put the button on a Form and click the button!
If you want to calculate number of days between days than you can use below built in function "DateDiff" which will solve it out. Datediff("D",,)
Ex. Datediff("D",L2,Z1)