The scenario I have is as follows:
Cell A1 - contains the name of the current month, e.g. "October"
Cell A2 - contains the value of the current year, e.g. "2014"
Cell A3 - contains the value of a given day, e.g "22"
I'd like to populate A3 with a formula that will give it the value 22 October 2014 and have this formatted as a date so I can perform comparisons and calculations in other cells - so along the lines of 22 + A1 + A2. I've tried using the CONCATENATE function but this doesn't let me format the cell as a date.
Is something like this even possible using the standard Excel functions?
You're looking for the DATEVALUE function. It can convert month names into a numerical date expression, which you can then format as a date (dd/mm/yyyy in the example below).
=DATEVALUE(A3 & " " & A1 & " " & A2)
As a bonus, this will also work if A1 contains short-form month names i.e. Jan, Feb, Mar, etc.
I just did a bit of testing, which showed that you can also drop the " " space delimiters entirely:
=DATEVALUE(A3&A1&A2)
In fact, just using -- to force Excel to treat the concatenated string as a numerical value works as well!
=--(A3&A1&A2)
So far, my testing has not found any instance where -- doesn't work as well as DATEVALUE. Leaves me wondering what the point of DATEVALUE is.
Try this:
=DATE(A2,MATCH(A1,{"January","February","March","April","May","June",
"July","August","September","October","November","December"},0),A3)
You can also use this formula
=(A1&A2)+A3-1
format result cell in required date format
Related
Data is extracted from the application. There is a text representation of data/time as
"Wed Nov 30 2022 09:30:00 GMT+0530 (India Standard Time)" (in text)
I am required to format this column as MS data/time type, instead of text
First:
Tried custom format.. but didn't work.
not able to teach "Wed" and "GMT..." part
Second:
Tried to break the words as
=MID(A1,5,20) [it gives "Nov 30 2022 09:30:00" ]
and then apply.
=TIMEVALUE(TEXT(RIGHT(B1,8),"HH:MM:SS"))
It worked and excel was able to understand it in time format as9:30:00 AM
But, when I applied similarly the Date format as
=DATEVALUE(TEXT(LEFT(B1,11),"mmm dd yyyy"))
It gave a Value error, not sure what to do next
Finally:
Is there a way to do it in one go?
the entire column can be formatted as a valid date and time.
I took inspiration from:
[question]: Convert text date/time to a real date time in excel
[blog]: https://support.microsoft.com/en-us/office/format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309
Kindly advise
There are many ways to do it, perhaps for now, I have tried this one,
• Formula used in cell B1
=LET(_string,TEXTSPLIT(MID(A1,5,20),," "),
_date,DATE(INDEX(_string,3),MONTH(INDEX(_string,1)&1),INDEX(_string,2)),
_time,TIMEVALUE(INDEX(_string,4)),
_date+_time)
Another way,
• Formula used in cell C1
=DATEVALUE(SUBSTITUTE(LEFT(MID(A1,5,20),11)," ",", ",2))+RIGHT(MID(A1,5,20),8)+0
DATEVALUE() wrapping not required actually,
• Formula used in cell C1
=SUBSTITUTE(LEFT(MID(A1,5,20),11)," ",", ",2)+RIGHT(MID(A1,5,20),8)
Use LET() to make it more readable,
• Formula used in cell C1
=LET(_extract,MID(A1,5,20),
_datepart,LEFT(_extract,11),
_timepart,RIGHT(_extract,8),
SUBSTITUTE(_datepart," ",", ",2)+RIGHT(_timepart,8)+0)
One more sleek way is using TEXTBEFORE() & TEXTAFTER()
• Formula used in cell D1
=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A1," ")," GMT")," ",", ",2)
Note: Since in Excel Date and Times are stored as number this will return as a number, The integer portion of the date serial number represents the day, and the decimal portion is the time, hence format it accordingly as per your need or regional settings.
I hope you are all well.
I have a question. I have a list with many payments listed on column A with dates (format day/month/year) in column B and I would like to use a formula which says something like
IF= A1 = Q2, "pay", "don't pay" , IF= A2 = Q2, "pay", "don't pay"...
Q2 means quarter 2
Could I define names for dates? For example Q2 would be 01/04/2021 - 30/06/2021 so all the dates within that range would be named Q2.
Best regards
You may try anyone of the approaches as explained below, the first one is using ROUNDUP & MONTH Function and the other one is using DEFINED NAMES.
First Approach ---> Using ROUNDUP & MONTH FUNCTION
• Formula used in cell B3
="Q"&ROUNDUP(MONTH(A3)/3,0)
• Formula used in cell C3
=IF("Q"&ROUNDUP(MONTH(A3)/3,0)="Q2","Pay","Don't Pay")
So you can see i have used two columns in the first approach just to make it understandable, therefore just wrap the formula in cell B3 within an IF logic as shown in cell C3 to get the desired output.
Second Approach --> Using DEFINED NAMES & SUMPRODUCT FUNCTION
• Formula used in Defined Names
=ROW(INDIRECT(--TEXT("01-04-2021","dd/mm/yyyy")&":"&--TEXT("30-06-2021","dd/mm/yyyy")))
So you can see I have Defined the Quarter 2 as _Q2 and the reason is a name must either begin with a letter, underscore (_), or backslash (). If a name begins with anything else, Excel will throws an error.
Therefore the formula used in cell D3
=SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))
The above formula creates an array of TRUE's & FALSE's and multiplies to return the corresponding values.
Now the above formula when wrapped within an IF Function it gives us the requisite output as desired,
Formula used in cell E3 (Same it can be done in one cell, to make it understandable i have used two columns)
=IF(SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))=1,"Pay","Don't Pay")
So this is how you can used a Defined names for dates in excel and then use the same within a formula.
This solution does not provide names for dates but it might meet your needs:
Make sure column A is formatted as a date, then use this formula to get the quarter from the month (this array allows you to set Q1 if it is not the same as calendar quarters):
="Q"&CHOOSE(MONTH(A1),1,1,1,2,2,2,3,3,3,4,4,4)
Then test the value of this column:
=if(C1="Q1", "Pay", "Do not Pay")
You could also create a cell at the top of your spreadsheet and name it current_quarter. Then you would type in the current quarter "Q1", "Q2", ... and your formula would be
=if(C1= current_quarter, "Pay", "Do Not Pay")
You are using standard calendar month quarters, so we can get the quarter number easily by dividing and rounding up.
=ROUNDUP(MONTH(A1)/3,0)
You can then use this number in your IF function.
=IF(ROUNDUP(MONTH(A1)/3,0)=2,"Pay","Don't Pay")
I'm using a vlookup against a table that has a generally-formatted column in the format "WORD NUMBER DATE" such as "Romeo 5M 06/16/2019". The reference is a helper column that I've created combining "Romeo" and "5M" and "06/16/2019". However, the date part needs to be formatted as text or else it won't match the lookup. This formatting is causing the #N/A error, despite a match. When I use =cell=cell2, it brings up "FALSE", given the formatting.
Help with this?
Thanks in advance.
I've already tried copy/paste formatting, and typing out the text in the cell makes the reference work so I'm assuming it's the formatting.
You can format the date in three separate cells. Assuming your date is in cell A1:
In Cell B1 - get the Year value
=YEAR(A1)
In Cell C1 - change the value to 2 digits if the month value is only 1:
=IF(LEN(MONTH(A1)) = 1, "0" & MONTH(A1), MONTH(A1))
In Cell D1 - change the value to 2 digits if the day value is only 1:
=If(LEN(DAY(A1)) = 1, "0" & DAY(A1), DAY(A1))
Then, in your aggregation formula, combine them like this:
= C1 & "/" & D1 & "/" & B1
If I'm reading your question correctly this should solve your issue.
Alternatively, if you need to change the cell format to text you may need to use vba code to perform some calculations for you which I can outline for you as well if this solution doesn't help you.
I need to extract the date from C2 and find the difference between the date in c2 and A1
The date is formatted as "Jul, 18 2015", any ideas? EDIT the database has a different amount of text per cell. Is there away around this so that i can apply the formula to every cell and pull the day/month/year?
you are going to need to go through a series of string manipulation and date time functions. Lets start by assuming your string is in the C2 cell. In order to do this we are going to work from the largest unit (years) to the smallest unit (days). You can do it in any order as it will all be lumped into once formula, but for the breakdown of steps its good to have an order.
Step 1) PULL OUT THE YEAR
=MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4)
That will give us the last 4 characters of the string after the second space which in this case is the year.
Step 2) PULL OUT THE MONTH
=MONTH(DATEVALUE(MID(C2,2,3)&"-"&1))
that looks at second character and pulls out the string 3 character long which is your month. It then converts it to a format that excel tends to recognize as a date short form by adding a - and the digit 1 to it. So in your case if would look like Jul-1. Datevalue converts this to an excel date serial, which we then pull back and grab the month from and in your case that is 7
If the above formula does not work for you it could be due to regional settings. If that is the case you can use the following:
=MATCH(MID(C2,2,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)
If you use this alternat formula , be sure to adjust the final equation accordingly.
Step 3) PULL OUT THE DAY
=TRIM(MID(C2,FIND(" ",C2)+1,2))
So the above formula finds the first space and then starts pulling then next 2 characters after it. Now since I do not know if the first of the month is 01 or just 1, it may wind up grabbing the space after the 1. The trim function removes excess spaces.
Step 4) BUILD THE DATE
The DATE function in excel requires the YEAR, MONTH, and DAY and converts those values in to the excel date serial. In this case we will convert:
=DATE(year,month,day)
to the following by substituting our equations from above:
=DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
The final touch is to ensure your cell is formatted as date and not General or some other format which will result as the date being displayed in an integer format.
Now assuming you date in A1 is in Excel format, you would simply add A1- to the front of the last formula to give you:
=A1-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
Now, if A1 is also in quotes like the C2 formula, repeat the formula for stripping the date out of C2 but use A1 as the reference and substitute it in for A1 in the last formula to give:
=DATE(MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,4),MONTH(DATEVALUE(MID(A1,2,3)&"-"&1)),TRIM(MID(A1,FIND(" ",A1)+1,2)))-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
FORMULAS USED
Text/String Functions
MID
FIND
TRIM
Date/Time Functions
DATE
DATEVALUE
MONTH
I have an Excel file which is exported from a Access database.
I have 25000 records and I will need to replace all of them.
The date column is not formatted (yymmdd). I need to change the date format from yymmdd to dd/mm/19yy. For the yy I need to add a constant value 19 in front of it so it would be 19yy.
I have only 1 date column per row
Is there any way to convert all the 25000 record's column formatted in yymmdd to dd/mm/19yy in a few clicks?. Thank you
This will give you the result as an actual date which you can then format as you wish using Excel's date formatting options.
=DATE(1900+LEFT(A1,2), MID(A1,3,2), RIGHT(A1,2))
If you don't need to parse it into a date value, but merely need to display a date in the format you identified, the following will work on a value in cell A1 (copy down to the rest of the 25,000 values as needed:
=RIGHT(A1,2) & "/" & MID(A1,3,2) & "/19" & LEFT(A1,2)
In my cell A1, I entered the value 981116. This formula converted it to 16/11/1998. I think that's what you're looking for, right?
Assuming data starts at A2 put this formula in B2
=(19&TEXT(A1,"00-00-00"))+0
Now format B2 in required date format, e.g. mm/dd/yyyy
and you can easily "fill down" all 25000 rows by doing this:
put cursor on bottom right of B2 (first cell with formula) until you see a black "+" - that's the "fill-handle" - double click and the formula will populate as far down as you have continuous data in the adjacent column
Note: you can probably omit the 19& if all your dates are after 1930 because the default is to treat any date written without the century as 1900s if it's >=30 or 2000s if it's <30 [although you can change that in regional settings]