Parsing string in Excel - date and time - excel

I have following problem:
I want to extract time interval from string like
time=10PM-12AM!991408111200000
The problem is, I need it in 24hrs format, so 10PM-12AM should be 22 and 00 in two different cells. I tried several solutions, but nothing worked for all possible intervals. Do you have any idea how can I do that? Thanks a lot!

This should work. Assume that your original string is on A1. The first code is for the first portion of the time. The second is for the time after the dash.
=TEXT(IFERROR(REPLACE(MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1)),FIND("PM",MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1))),2," PM"),REPLACE(MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1)),FIND("AM",MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1))),2," AM")),"HH:MM")
=TEXT(IFERROR(REPLACE(MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1)),FIND("PM",MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1))),2," PM"),REPLACE(MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1)),FIND("AM",MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1))),2," AM")),"HH:MM")
The reason this is so long is because I am not sure if your data always comes up with four characters for the time. For example, if your data has time=3PM-6PM this should be smart enough to understand that there is less spaces in between. This also assumes that the exclamation mark just happened to be randomly there rather than always there.
Let me know if you have a problem.

Related

How to take number input and convert to time in excel

I am making an airplane reservation system on java. i got a sample database from online. only problem i have is the way the time is inputted.
and some times are 917 , or 22 , or 2. there is no 0 so i cannot just try and put a semicolon after 2 spaces.
Any one know if their is a way to do this, or some work around.
You can try:
=--TEXT(A1,"00\:00")
and format the result as "Time"
Edit:
I note you have changed your specifications to include that the times may be entered as the hour only: eg: 2 or 22. Try the revised formula below to handle that:
=--TEXT(IF(A1<=24,A1&"00",A1),"00\:00")
You can use the following formula:
=TIME(LEFT(A2,LEN(A2)-2),RIGHT(A2,2),)
A2 = the arrival time cell that you want to convert.
Also, make sure to change your output column to whatever time format you're looking for. Screenshot of results in action included.

finding time difference with 1 cell

I recently pulled a huge amount of data into a csv file, as a result a large amount of data is being formatted like this:
xx:xx-xx:xx - 'text'
The problem i'm having is this is all in one cell, I've tried looking online without much luck so basically wanted to know if it's even possible to find the time difference between xx:xx-xx:xx even if they're stored on the same cell? If not, is there a way to split these times into different cells en mass?
edit:
I've managed to remove the text from the cell, I now am left with 1 cell containing ranges similar to:
Please try, formatted as Time:
=MID(A1,7,5)-LEFT(A1,5)
If that does not work then check for leading spaces. Won't suit if times are late/early order, nor if spanning midnight.
Edited so there should be no need to strip out 'text'.

Comparing values with some alphanumerics

I've looked through the forums but couldn't find any questions (with answers) that helped. Any guidance would be appreciated.
I'm working on an Excel/Access project that cross references error codes. The codes are twelve digits long, with the first half and second half that need to be sortable. 99% of these codes are entirely numeric, but the 1% that includes letters is really screwing me up.
For example, a common error code might be "386748000123". This would be split into "386748" and "000123", with the first being the code for the type of system and the second being the type of error.
But then the 1% are something like this: "0957AB003A41". "0957AB", and "003A41".
If I format the columns (in Excel and Access) as numbers than the numeric comparisons are far easier, "000123" equals "123". If I format the column as strings than I can compare the alphanumeric values but then "000123" and "123" stop crossing.
The possible solution I've come across is utilizing the Val function inside an Access query to purely compare values but I've never used it and it seems like only a partial fix. Val ignores the strings, which means "0957AB" will have the same value as "0957XY" - and that doesn't work for this project.
I'm sure many of you have had similar issues, so I'm hoping to get some ideas on different ways the problem has been approached and resolved.
You have not provided a minimal sample of the data and also the output, also there is no code that I can amend it for you, but the only part that you are having problem is comparing the alphanumeric ones, you should format all of your data as strings and then compare. to make 123 be equal to "000123" you need to just format the numeric ones as string as below:
format(123,"000000")
which will give you "000123"
Edit
from you comment I learned that the problem is the key that is always or often a number, format will return the proper string for comparison, if it is already a 6-character string it will return itself so there would not be a problem:
do something like this:
if format(key,"0000000")=format(code,"000000") then
'do something
end if

How to use "IF" code with multiple conditions?

I have 5 columns of data with around 50,000 rows. This is the ambulance response times to an incident. I am trying to figure out the total number of incidents as multiple ambulances respond to a single incident. The 'IF' function has been useful upto a certain extent where the multiple ambulances reached at the same time but when it is not at the same time, it considers it as a different incident. I would like to add a buffer of 20 minutes but I am not able to figure out how to incorporate that. The second problem is with the incident number. The incidents 2014-014374-006, 2014-014374-009 are the same, just the ending numbers are different. How do I differentiate? Can I do it in excel or other platforms?
http://imgur.com/a/30VHl
To return the incident number, use a formula like this: "=IF(ISERROR(SEARCH("-",D5,SEARCH("-",D5)+1)),D5,LEFT(D5,SEARCH("-",D5,SEARCH("-",D5)+1)-1))" where D5 is the cell with your incident number.
What this formula does is it first creates an if statement that will allow you to determine if the incident has the second dash or if it doesnt. If it doesn't, then it will return the value in the cell. If it does, it will return the text to the left of that dash. The search function looks for a substring, and by nesting a search and adding "1" to the value of the first search, we are looking for the substring that comes after the first one is found.
It is a rather confusing formula the first time you use it, but it works like a charm once you understand it.
I will see if I can figure the dates out. That might be more difficult. If you can simply use the incident number for this, you will likely have an easier time.

Amazon Cloud Search - get places by time and date

I am using Amazon CloudSearch to store a large set of places.
Each place has a opening time and a closing time, for each day of the week.
I need to retrieve places by current time. How do you suggest to model the index?
I am thinking to solve the problem by creating 7 text indexes in which I specify, for each day of the week, the valid hours.
For example, if a place is opened from 9 am to 13 am, in the index "monday" I will write the string "9-10-11-12". Then, filtering by bq=monday:'10' or bq=monday:'16' I will have only the places that at the specified time are opened.
Any other idea? My solution seems working but would suggest me another approach?
First, I wouldn't use multiple indexes.
You could use your approach, but just make the time in hours from the start of the week. So, Monday would be 0-23, Tuesday 24-47, etc. Or you could just have 7 fields, "monday_hours", "tuesday_hours", …
You could also use uints, instead of strings. Not better, but different, might be worth benchmarking.
With uints you can use range queries. If the document contained the fields "open" and "close" and you want to know if it's open between 10 and 12.
&bq=(and open:..12 close:10..)
One issue remaining is that CloudSearch's range searches are inclusive of endpoints. So I think this will show a false positive if the store opens at twelve. Technically, the ranges overlap, but not usefully. To fix that, I'd do two things. First, I wouldn't go by hours, I'd use minute-of-the-day as the value in the field (0 to 1439). Then add one to the starting range, and subtract one from the end.
Using uints will perform differently from using text fields. I'd definitely benchmark them to see which one works better for you.

Resources