How do you parse a substring from an Excel cell? - excel

I have a column with the following values:
month
201201 // means January of 2012
201102 // means February of 2011
201203
201304
...
201307
201106
I need to create a new column that would be convert the last two numbers in the month column into the name of the month, so that 201201 will become Jan-2012, 201106 should become Jun-2011.
How can I parse the last two characters?

This gives you the formatting you want:
=TEXT(DATE(LEFT(A1,4),RIGHT(A1,2),1),"MMM-YYYY")

=DATE(MID(A2,1,4),MID(A2,5,2),1)

You can use LEFT and RIGHT functions and concatenate the results. Assuming the first value is in A2:
=(1&"-"&RIGHT(A2,2)&"-"&LEFT(A2,4))*1
And format the cell as mmm-yyyy.
This assumes that your regional settings have dates as dd/mm/yyyy format.
Otherwise, you'll have to switch the month and date around.
=(RIGHT(A2,2)&"-"&1&"-"&LEFT(A2,4))*1

Related

Convert HH:MM values to H in the same column

Is there a way for me to format a column where the values I enter in the format HH:MM (elapsed time, not datetime) are converted to hours in decimal, preferably in the same column via some custom formula?
For example,
HH:MM
H (Decimal)
07:39
7.65
02:15
2.25
06:00
6
At the moment, I manually calculate the equivalent and enter them into the column but it would be nice to directly copy a timestamp and have the column automatically format it but I couldn't see an option for this in Date/Time formatting settings.
Simply multiply your hh:mm durations by 24, ensuring that the cells where you want the decimal hours returned are formatted as 'Number'. Or to force formatting as a number using a formula: =text(duration_cell*24,"#.##") where duration_cell is a cell with the duration in hh:mm format.
There is no way to do that I know of because Excel stores times/dates as floats. Each 24 hour period equals 1, therefore 7:33 equals .31458 Therefore, you won't be able to do this without a helper column.
You can do this with either #The God of Biscuits answer, or alternatively your helper column can have the formula:
=(A1*24)
and you set that column's cell format to Number.
All date and time is a format of a double value.
Time is the amount after the comma.
And all in front of comma is days since 00.01.1900.
Meaning 07:37:00 = 0,32 days.
Excel have a ways to pull the amount of hours with =HOUR('Your referance date time cell value')
You can aply this formula: =HORA(A2)+(MINUTO(A2)/60)

Formula to convert quarter-year to MM/DD/YYYY in Excel

I want to convert a column of dates in QTR/YR format to MM/DD/YYYY format, using the first day of the quarter (the first days of the four quarters are Jan. 1, April 1, July 1 and Oct. 1.) How can I go about doing this?
Example:
4Q14 should become 10/01/2014
3Q14 should become 7/01/2014
2Q14 should become 4/01/2014
and so forth.
Try this:
=Date(Right(A1,2)+2000,CHOOSE(Left(A1,1),1,4,7,10),1)
If cell A1 contains the text, then
=DATE(2000+RIGHT($A$1,2),-2+3*LEFT($A$1,1),1)
is one way. That will yield a number that you can format as a date, using the format of your choice.

Excel: Check cell for date

Short story short:
I want to check the cell C21 if it contains a date. I can't use VB cause it's deactivated by GPO.
Used this from this page
D21 contains this:
=WENN(ISTZAHL(DATWERT(C21));"date";"no date")
in english
=IF(ISNUMBER(DATEVALUE(C21))...
C21 this:
=HEUTE() # in english: =TODAY() Maybe other dates later, but allways in the correct format
but it allways returns "no date"
Use this: =IF(LEFT(CELL("format",C21))="D",..,..). Learn more about CELL formula here.
In your example =TODAY() already a real date and not a date stored as text, so doesn't make too much sense to use DATEVALUE there.
Update
Here are some example dates and how CELL recognize them:
format value output
dd/mmmm/yyyy 12/June/2015 D1
dd/mm/yyyy 12/06/2015 D1
yyyy 2015 G
general 2015 G
dd/mm 12/06 D2
mmmm June G
dd mmmm yyyy 12 June 2015 G
Note: CELL is not volatile, so if the format of source cell is changed it won't be refreshed automatically, you need to either recalculate your sheet / book, either open the formula and press enter (also automatice recalculation initiated by any other volatile formula will cause it to refresh).
Use this formula, the expression will return TRUE if cell A1 contains an invalid date.
=ISERROR(DATE(DAY(A1),MONTH(A1),YEAR(A1)))
This formula works by evaluating each component part of the date: DAY, MONTH and YEAR and then aggregating them using the DATE function.
ISERROR will the catch any errors by returning TRUE (invalid) otherwise FALSE (valid).
Obviously the date value in cell (A1) must contain values >= 01/01/1900.
Useful for "Conditional Formatting".
Excel stores dates as numbers. 1 is 1-Jan-1900.
When it comes to numbers in a cell, Excel cannot tell if a number is meant to be a number or a date.
Today is 11/06/2015 as a date and 42166 as a number. For the consumer of a spreadsheet, the cell can be formatted to display the number as any number format or as a date. Excel formulas cannot tell whether the number in that cell is "meant" to be a date.
So, there is no Excel formula that you can use in a spreadsheet that will tell you if cell A1 is about 42166 widgets or if contains the date of June-11-2015.
Some of provided answers, checks cell format, which will not considers cell value, as you can format differently each cell no matter of its content, for checking if a cell value is date you can use this:
if(ISERROR(VALUE(c21)),"No Date", ----do staff for Date ----)
or shorter version which just will inform you "no date" status. If a date entry is find, it will return its numerical value instead:
IFERROR(VALUE(c21),"No Date")
hope this helps,
Cheers,
M
use the following formula ...
=IF(NOT(ISERROR(DATEVALUE(TEXT(C21,"mm/dd/yyyy")))),"valid date","invalid date")
I think it will solve your problem.
If the value is a string this method would work.
TEXT(DATE(VALUE(RIGHT(AI8,4)),VALUE(MID(TRIM(AI8),4,2)),VALUE(LEFT(AI8,2))),"dd.mm.yyyy") = AI8
Just wanted to add to the discussion that although you can check with a date(year;month;day) it will give you false positives, since the way it works is that it seems to just roll over values that exceed the logical limit, i.e. if you have the date 99-12-35 it will assume that you meant to write Jan 4th 2000, since that is the 35 - the 31 days of December. In other words, you will find some errors, but not all. Same goes for months exceeding 12.
try this formula (depends on date format):
=IF(DATE(TEXT(C21;"yyyy");TEXT(C21;"mm");TEXT(C21;"dd"));"contains date";"doesn't")
I tried every solution posted but none of them work if there are empty cells in the date cells, so I added a check to GBGOLC's answer and now it works with empty cells:
=IF(NOT(OR(ISBLANK(C21),ISERR(DATE(DAY(C21),MONTH(C21),YEAR(C21))))),"Yes it is a date","Not a date")

Excel: Convert calendar week (format ww.yyyy) into date

I need to convert an Excel calendar week date into the actual date.
Excel calendar week format = ww.yyyy (e.g. 31.2014);
Expected output = 7/28/2014 (return the Monday of the week)
What formula should I use ?
It's a bit of a pain: there's no direct function. If A1 contains the year, and A2 contains the week number then,
=MAX(DATE(A1,1,1),DATE(A1,1,1)-WEEKDAY(DATE(A1,1,1),2)+(A2-1)*7+1)
will return the date corresponding to the Monday of that week in that year.
To test it, use =WEEKNUM() and =YEAR() on the computed result, along with =TEXT(,"DDD") to prove it's a Monday.
If #Bathsheba's response works for you, you can do everything in cell B1 with the following command
=MAX(DATE(LEFT(B1,FIND(".",B1)),1,1),DATE(LEFT(B1,FIND(".",B1)),1,1)-WEEKDAY(DATE(LEFT(B1,FIND(".",B1)),1,1),2)+(MID(B1,FIND(".",B1)+1,2)-1)*7+1)
This allows you to put YYYY.WW in B1 and it splits it up for you in the calculation.

Convert text to date in Excel

Currently I exported some data, from a database using a query in which each row for a "comment" column begins with a date formatted as MM/DD/YY.
I used the =LEFT(TEXT,8) function to only extract the date but it happens that the some of the dates are formatted inconsistently so we may have some that are M/D/YY where the month or day isn't two digits, this will then include a ';' as a separator since it is less than 8 characters.
Is there a way I can format the text so the ';' is excluded? That way I can sort the data.
I think the DATEVALUE function does most of what you need. It takes in many different date formats (M/D/YYYY, MM/DD/YYYY etc) and converts it to an excel date (i.e. # of days since 1/1/1900).
The formula below says:
If the date is clean then just apply DATEVALUE function
If there is an error, just use the part to the left of the ';'
Assuming 9/1/2013 is Cell A2:
Input Data Sortable Excel Date
---------- -------------------
9/1/2013; =IFERROR(DATEVALUE(A2),DATEVALUE(LEFT(A2,FIND(";",A2)-1)))
09/2/2013; 9/2/2013
10/1/2013; 10/1/2013
10/10/2013 10/10/2013
I've made a live Excel sample here.
Assuming your text looks like this: ;1/;2/13 or 1/2/13;; or ;;1/2/13
You can use substitute like this:
=SUBSTITUTE(A1,";","")
The result will be:
So if date is either the first 6, 7 or 8 characters of A2 you can get the date with this formula
=LOOKUP(10^10,LEFT(A2,{6,7,8})+0)
format result cell in required date format
As the result is a valid date you can sort these as you would sort numbers

Resources