I have date format in the following manner in the excel which is in string format:
Apr 1, 2016 12:37:06 PM
Apr 2, 2016 12:00:00 AM
Apr 1, 2016 9:50:22 AM
Apr 1, 2016 12:09:38 PM
Apr 1, 2016 6:53:03 PM
Apr 1, 2016 1:02:10 PM
I have tried converting it from general to date however excel still does not recognize it as date format. Need your advise as what can I try more to solve this.
Thanks in adavance !!
try =DATEVALUE("date string").
hope this helps
here is how it works
if still didn't work, then it has to do with windows date time setting.
Open Region and Language setting from Control Panel. Change the Long Date format to "MMMM dd,yyyy". Because this is the format your date string is formatted. You have to do this to get DATEVALUE() in excel to work. Now go back to your formula and see if it works.
After that, copy paste the formulas as value. Then you can change back to your preferred long date format again (or just leave it).
Couple of options for you:
Option 1
Text to Columns built in excel feature
Select all Dates for starters. They need to be in one column. On the Data ribbon, select Text to Columns. Light green back ground in the image above.
On the ensuing window that pops up select Fixed Width. Then select Next.
Adjust the columns so you get either a single column or the date in one column with the time in the other. Then select NEXT.
In the bottom preview window select the first column. Then up top select the Date radio button and from the pull down select MDY format. when ready click on FINISH button
Option 2
Formulas
Ripping out the text from the string and rebuilding the date using some ugly long formulas. So we are going to do this in parts so you can see how the big ugly gets made. When we are done we will copy the smaller formulas into one formula which will be big ugly and hard to read.
One of the annoying thing is you have the month as an abbreviation. Somewhere off to the side you will need to build a table and put all the abbreviations in one column and the corresponding month number in the column to the right. There may be other ways to do this but this is what I am going with for now.
(AA) | (AB)
Jan | 1
Feb | 2
Mar | 3
Apr | 4
May | 5
Jun | 6
Jul | 7
Aug | 8
Sep | 9
Oct | 10
Nov | 11
Dec | 12
So we can either work from biggest (Year) to smallest (seconds) or from left to right. lets tackle this starting from the left.
First thing first we need to pull the month out. Thankfully its on the LEFT side and we know its only 3 characters long. So we can go straight to the excel formula and hard code this in. And alternative approach would be to find the space. So first formula to find month is
=Left(A1,3)
Since we are going to need to know the number of that month we can convert it with a VLOOKUP function (INDEX/MATCH is another option). Lets put this in column F for now.
=VLOOKUP(Left(A1,3),$AA$1:$AB$12,2,0)
That should return the number 3 for us. you will have to adjust the AA1:AB12 to suit where you put the table.
Next we are going to pull the day. We know its 1 or two characters to the left of the first comma. We will use the FIND to determine where that is since it is not in a fixed position.
=FIND(",",A1)
So we know the date will start either 1 or 2 characters to the left. No harm in taking two as it will be a space or a number. So now lets use that knowledge with the MID formula and place the following in column G for now:
=--MID(A1,FIND(",",A1)-2,2)
the -- changed the text to a number (they are not actually needed in this case). So the next one is a little trickier but still doable. We need to find the Year. wouldn't you know it, its a fixed 4 characters long and starts just after that same first coma. So lets reuse our previous formula but tweak it a little and put the following in column H for now:
=--MID(A1,FIND(",",A1)+2,4)
Well now that we have our Month, Day and Year as numbers we can build our date using the DATE formula which we can drop in say column I:
=DATE(H1,F1,G1)
now if you thing you are ready to get started on the big an ugly we can substitute each of our previous equation into our date equation so its all done in one cell. That big formula is going to look as follows:
=DATE(MID($A1,FIND(",",$A1)+2,4),VLOOKUP(LEFT($A1,3),$AA$1:$AB$12,2,0),MID($A1,FIND(",",$A1)-2,2))
Now when I say all in one cell, I should add the caveat that you do need that helper information of the list of months...though there is a way around that too. So that takes care of the date process. now to do the time is very very similar.
We have two options The first option may not work for you since the datevalue formula did not work for you.
Option A - TimeValue
The nice thing about your time set up, is that the time is either 10 or 11 characters long from start to finish and if we take all 11 when its really only 10 we again are just snagging a space. So lets grab the RIGHT time and place this formula in the K column:
=TIMEVALUE(RIGHT($A1,11))
Now if that option does not work for you then we break it down the same way we did for the date.
Option B - Stripping Time
So lets look at patterns to see what we can figure out...that first ":" looks like a great identifier so lets find it the same way we did up for the date. Let build our time formula in column N:
=FIND(":",A1)
Let sub that straight into the MID formula to pull the hour
=MID($A1,FIND(":",$A1)-2,2)
And in Column O we will do the same for minutes and again with a bit of tweaking
=MID($A1,FIND(":",$A1)+1,2)
And since we know that the minutes keep a leading zero for single digit minutes we also know exactly where seconds are going to start. Lets put this formula in column P:
=MID($A1,FIND(":",$A1)+4,2)
So you might be wondering what to do about the AM/PM Lets grab that and put that in column Q
=RIGHT($A1,2)
So now that we have all that information what are we going to do to build the time. Well first things first is you need to know that Excel like 24 hour clocks. However it really saves it time as a decimal of a day. So 12 noon is actually stored as 0.5 or half a day. Another important thing to know is that the official supported time range for Excel is 00:00 to 23:59. There is no 24:00. now having said that 24 as an hour makes VBA crash unless you specifically deal with it in some special code. You can however get away with supplying 24 as an hour in excel formulas and get away with it sometimes. ok enough with the time lesson let build this final formula in column R:
=TIME(N1+IF(AND(Q1="PM",N1<>"12"),12,IF(AND(Q1="AM",N1="12"),-12,0)),O1,P1)
You will note there is an IF formula in there that deal with the AM PM as well as the special case of the 12 hour. The 12 is in quotes because N1 is a string and I had not converted it to a number.
now for the uglyness of back substituting our formula so it all in one cell.
=TIME(MID($A1,FIND(":",$A1)-2,2)+IF(AND(RIGHT($A1,2)="PM",MID($A1,FIND(":",$A1)-2,2)<>"12"),12,IF(AND(RIGHT($A1,2)="AM",MID($A1,FIND(":",$A1)-2,2)="12"),-12,0)),MID($A1,FIND(":",$A1)+1,2),MID($A1,FIND(":",$A1)+4,2))
And yeah that is so easy to read! I asked if you needed this in one column or two. Well you have the full formula for the date on its on and the full formula for time on its on. So if you need them together here is an interesting tid bit of information. Since Time is stored as decimal days, that means everything to the right of the decimal is time. It also means that everything to the left (or the integer portion) are days. So to have date time in one column, you just need to add the two formulas together...or as I refer to it as, the really big ugly equation...or at least one of the many that fall into that category:
=DATE(MID($A1,FIND(",",$A1)+2,4),VLOOKUP(LEFT($A1,3),$AA$1:$AB$12,2,0),MID($A1,FIND(",",$A1)-2,2))+TIMEVALUE(RIGHT($A1,11))
or if time value did not work for you
=DATE(MID($A1,FIND(",",$A1)+2,4),VLOOKUP(LEFT($A1,3),$AA$1:$AB$12,2,0),MID($A1,FIND(",",$A1)-2,2))+TIME(MID($A1,FIND(":",$A1)-2,2)+IF(AND(RIGHT($A1,2)="PM",MID($A1,FIND(":",$A1)-2,2)<>"12"),12,IF(AND(RIGHT($A1,2)="AM",MID($A1,FIND(":",$A1)-2,2)="12"),-12,0)),MID($A1,FIND(":",$A1)+1,2),MID($A1,FIND(":",$A1)+4,2))
Now this is just one solution on how to break it down with formulas. There are other options or route I could have gone at a couple of steps, but it should work for you regardless of what your system settings are. Here is a screen capture of the results on my system. note I hid empty columns that were not in use in order to make the image narrower. Column T has custom formatting of
mmm, d, yyyy h:mm:ss AM/PM
applied to it.
Option 3
VBA
I am sure someone will supply at some point. And look it happened before I could get to that stage! I don't know why 8)
As for the VBA solution, you can open VBA editor, add a new module and paste this code:
Function STRTODATE(ByVal dcell As Range)
Dim datecon As Date
datecon = dcell
STRTODATE = datecon
End Function
then you can use STRTODATE as a formula. Only really helpful, if it's one off. If it's something you'd do regularly on different files, then it can be annoying to paste this code to every workbook.
Related
Let's say we have time slots documented in which a production line was running. In between each product maufactured are time slots in which the machine was idling.
I now want to plot the machine status over time, basically as a boolean value (running vs idling).
I get the machine log and need the chart on the right.
The machining duration will ultimately be logged including seconds and may vary for each product.
The first - and probably biggest - challenge for me is to find a smart way to extract the status from the time stamps. My current first step ist to create a table row for each minute and use the if statement in H4 to check wether article 1 was being manufactured.
IF(AND([#Time]>Machine_log[#Start],[#Time]<Machine_log[#Finish]);;)
However, since the final list will range over 24 hours or more and the number of articles quickly reaches 50 and more, I would love to avoid using nested IFs on this one..
I'm thankfull for any input and open for inspiration :)
Thank you all in advance!
PS: Anyone know how a better way than a scatter chart with two values per X-Value to display the chart as vertical lines/right angles like this?
One option is to add only those points that are necessary to the Status extraction table (which I named "Status"). (I named the Machine log table "Log").
Note: it looks like you are using a semicolon list separator, so you'll need to change the commas in the formulas below to semicolons.
Formula for the Time column:
=IF(ROW()=ROW(Status),MIN(Log[Start])-1/144,IFERROR(INDEX(Log[[Start]:[Finish]],INT((ROW()-ROW(Status)-1)/4)+1,MOD(INT((ROW()-ROW(Status)-1)/2),2)+1),MAX(Log[Finish])+1/144))
Formula for the Production running? column (enter into H4 and fill down):
=IF(SUMPRODUCT(--(Log[[Start]:[Finish]]=[#Time])),IF([#Time]=G3,3-H3,H3),1)
These formulas will pad your plot with 10 minutes of off time on either side.
To answer your question about avoiding two points for each x-value: no, each point on the plot has to have a corresponding data pair.
UPDATE IN RESPONSE TO COMMENT: I failed to mention that the above solution assumes the time data in the Machine log table are in ascending order. This means that if your data span more than one day, they will need to contain a date component or you can get plots where the line crosses back to the beginning. For example, if you have 23:57:00 followed by 00:10:00 with no date component, Excel treats these as 11:57 pm on 1 January 1900 and 12:10 am on 1 January 1900. (To see this, change the format to "General", and you'll see the values that Excel uses to encode date-time aren't in ascending order.) The solution is to enter the dates as "8/16/2020 23:57:00" and "8/17/2020 00:10:00" in the formula bar. If you're copying over from another data source, the date needs to be copied with the time. If the dates and times are in separate columns, your Start and Finish columns would each be a date column plus a time column.
I'm working on an excel 2010 sheet where I mark down the date and time an event happens. The date is in one column, and auto formats to 17-Nov when I would type in 11-17 (I was fine with this). The time is in a separate column.
I am trying to find the average time an event occurred, without regard to the date, so I would use =AVERAGE(C1:C10). However, I only receive a date back (like 17-APR).
I did not format the cells before I began to enter in data, and I would simply type in a 3:27pm event as 1527, and no reformatting would happen.
Now, when I attempt to reformat the column to hhmm, all the numbers entered so far turn to 0000. When I try to edit the 0000, it is formatted as 6/13/1906 12:00:00 AM.
What I want to do is have the time formatted as hhmm and not include a date in the cell, and be able to run formulas on it, such as the average time an even occurred.
Summary:
*Currently time is entered simply as ####. I entered 3:27pm as 1527.
*Trying to reformat the time column results in 0000 in all cells in the column that previously had a ####.
*Modifying the 0000 displays as 6/13/1906 12:00:00 AM
*I want to format the time as hhmm so I can simply type in 2357, and have it display as 2357, but understand I mean 11:57pm, and let me take averages.
*Hell, even being able to enter 1547 and have it auto format to 15:47 or 3:47p would be great.
Thanks for reading my question!
An easy way to apply an autoformat (though Excel won't see it as a true "Time") is to go into Format Cells>Custom> and use ##":"##. This will turn 1245 into 12:45. Mind you, this will be a text string so if you copy it to another cell and then apply a time, it will show as 12:00:00. Excel will also not be able to run formulas on it, but it's a quick and dirty way to make it look pretty.
Another option is to have a formula such as =TIME(LEFT(A1,2),RIGHT(A1,2),) where A1 would be replaced with the cell you are actually referencing. This will convert the number to a time that Excel will recognize as a time allowing you to run other functions on it, but requires another column.
If you are entering the times as 4-digit numbers, you'll need to do a calculation to get the hours and minutes, then use the TIME function to get an actual time:-
=TIME(A1/100,MOD(A1,100),0)
Another way is
=LEFT(A1,2)/24+RIGHT(A1,2)/1440
but then you have to format the result as a time.
Excel sees a number like 1547 as approximately 4 years on from 1st January 1900 if you format it as a date, so it will come out as something like 26/3/1904 in UK format or 3/26/1904 in US-style format.
Note that the time function can only give you values up to 23:59:59 (stored as 0.999988426), but the second method will give you a datetime value with one or more days as the whole number part. This can be useful if you want to do calculations on times spanning more than one day.
The above behaviour is because dates and times are stored as real numbers with the whole number part representing days and the decimal part representing fractions of a day (i.e. times). In spite of misleading information from Microsoft here, dates actually start from 31/12/1899 (written as 0/1/1900) with serial number 0 and increment by 1 per day from then on.
How do I work with a Date Time -0500 value?
I have a sheet that has a value that looks like this:
2016-05-12 21:51:13 -0500
I want to be about to use it.
I want to filter all records that are greater than
2016-05-12 00:00:01 -0500
But I do not know how to work with this value.
Use this formula:
=--LEFT(A1,LEN(A1)-5)
Then format it like this
yyyy-mm-dd hh:mm:ss -\0\5\0\0
Then you can copy and paste the values and formatting where you want it
You need to convert the data into Excel date/times. With data in A1 in B1 enter:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))
and format to display both date and time:
Let's presume for a moment that for some unknown reason Excel could not identify your string as a valid date time. You can always go back to basics and break your string down into its components. Let's start off and assume that your date time and offset string are in cell A1.
Step 1) Strip out the year
=left(A1,4)
Step 2) Strip out the month
=MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1)
That bad boy of a formula looks for the first - and the second - and based on that information finds the starting position to start pulling characters from and figures out how many characters to pull.
In your case we could have set it to pull two characters and had it start at character six as there is no variation to your date format. However, in a generic sense where there are not always leading zeros in the month, or sometimes you were flipping between four characters for the year and two characters for the year, the above would still work.
I am also assuming that month is the middle value (05) and you are not talking about December 5th here.
Step 3) Pull out the day
We could have used a similar approach using mid here, and again we could have hard coded it (wait, I did hard code two character return). Instead for a little flavour I used a right left sequence.
=RIGHT(LEFT(A1,FIND(" ",A1)-1),2)
Step 4) Pull out the time
Now you could go through the whole process and pull out hours, minutes and seconds, but Excel is usually pretty good at recognizing a time format as there is not much variation to it. Also this gives an opportunity to see a new formula for dealing with string manipulation.
Now since your time format was constant, I got a little lazy knowing that your time was always going to be eight characters long since your format always has a leading zero. As such, I used the following:
=TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Basically, I grabbed the whole time, HH:mm:ss, and dumped it into timevalue (note there is also a datevalue). Timevalue will attempt to convert a string in time format to Excel time format as a decimal value.
Now as previously noted, if all those times are all stamped with the same -0500, just ignore it.
To get all that date and time converted into a single cell we would take each of the date parts and drop them into the DATE function and then add the time component on. In Excel speak that looks like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Now if you want that to display with the -0500, look at Scott's answer for formatting. If you want to convert the time to local time and get rid of the -0500 then you would need to add -5 hours to the above formula which would look something like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+time(-5,0,0)
And if we were not so lazy and did not want to hard code the time, it would look more like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+TIME(LEFT(RIGHT(A1,4),2),RIGHT(A1,2),0)*IF(LEFT(RIGHT(A1,5),1)="-",-1,1)
My situation is like this.
I got this spreadsheet that is getting a lot of inputs of hours when something happened (the vertical table on the right in the picture- every time something happened it saves the time) in the 2 lines of the "factory"
Also, the hour that the "factory" was opened is entered in cell O4 (this case 05:30)
when i enter the opening hour the table below changes itself automatically from the open hour i entered.
Now, my problem is that I got this horizontal table (divided it to 2 tables 1 below the other so it can fit in screen better). In this table I want to show how many instances in each hour.
The rule is for example everything between 14:30 to 15:30 is going for the cell 15:30 and so on.
The formula in each cell on the horizontal table is:
=COUNTIFS(A2:A30,">"&N7,A2:A30,"<="&M7)
That example is from cell M8- every cell just checks how many in the range are between the hour before and the hour now. (cells N7 and M7)
The PROBLEM is only in midnight, in this configuration for example every instance that will be between 23:30 to 00:30 will be ignored by excel, i need to fix it, now every time the cell that contains midnight is empty.
How do I fix it?? I really need help on that.
(wanted to post a picture but it wont let me cuz im new :-( )
Since only interested in times, and only displaying times, add 1 to the relevant data (ie all those starting 00:).
An easy way to do so is to enter 1 in a cell somewhere, copy that , select all the data to be adjusted and Paste Special, Operation, Add, OK.
You can do that (as far as i understand it) by additioning two countifs with a simple "+" like this:
=countifs(range1;criteria1a;range1;criteria1b)+countifs(range2;criteria2a;range2;criteria2b)
where
range1 is the previous column and criteria1a/b is 23:30 < x < 24:00
range2 is the current column and criteria2a/b is 00:00 < x < 00:30
or something similar
PS: and happy new year to eastern Europe (UTC+3) !
Have a list of dates in excel in the format (this comes originally from csv):
23/11/09 07:27:02
23/11/09 08:01:50
23/11/09 08:38:58
23/11/09 09:40:01
What I want to do is count the number of these falling between hour blocks, like 7-8, 8-9, 9-10 etc
Not sure how to get started, but one idea was just to put logic statements comparing the dates between these blocks, then adding the total "trues"
I can't get it to compare properly. When I type it the hour block marks,
e.g. 23/11/09 08:00
excel actually shows that as
23/11/2009 8:00:00 AM
and the compare doesn't work. Well actually it does the opposite of what it should.
that is:
=IF(C5>L1,IF(C5<M1,TRUE,FALSE),FALSE)
C5 being date in top codeblock, L1 and M1 being the hour blocks I manually entered in the second code block.
Has anyone got any ideas?
=hour(a1)=7
will return true if the time of the date/time value in cell A1 is between 7 and 8 (AM) and will otherwise return false.
Excel stores dates as number of days since 1900 or 1904 depending on your setting and the time as a fraction of the days. So 11:59 am 4th of July 1960 is held internally as '22101.4993055556'.
As such you cannot do plain charactrer string comparisons on dates. However ther ar lots of nifty time/date functions available to you.
You probably want :
=IF(HOUR(B1) > 8,IF(HOUR(B1)<12,"YES","NO"),"NO")
You should use Excel functions, like HOUR(), to extract the parts of the times, and apply the logic tests to those extracted values.