Excel convert date to text retaining date layout - excel

I have rows containing every Monday and Sunday in an entire year, (with variations on when a month starts and ends) like so,
11/05/2015 18/05/2015 25/05/2015 01/06/2015 08/06/2015
17/05/2015 24/05/2015 31/05/2015 07/06/2015 14/06/2015
However these are in the date format, and I need them in a text format, but so they still read in the dd/mm/yyyy format, not like 42125.
Further up my document, each column header should read dd/mm/yyyy-dd/mm/yyyy using each of the dates shown in my first example, and I was hoping to achieve this using the formula =A30&"-"&A31 and so on. So the desired outcome should read,
11/05/2015-17/05/2015 18/05/2015-24/05/2015
11/05/2015 18/05/2015
17/05/2015 24/05/2015
However using the =cell&cell formula im left with
42135-42141 42142-42148
11/05/2015 18/05/2015
17/05/2015 24/05/2015
I have to create these headings for 2 years worth of dates, and trying to avoid typing every heading out manually, is there a way to achieve this?

Use the TEXT function which comes with Excel.
Assuming cell A1 has "11/05/2015", use the following formula in cell B1:
B1=TEXT(A1,"dd/mm/yyyy")
This takes care of the first part of your question. For the second part, you can use the CONCATENATE function. Assuming that B1 and B2 contain dates as text, you can join them together using the following formula:
=CONCATENATE(B1, "-", B2)

Try converting those values to text before concatenating:
=TEXT(A1,"dd/mm/yyyy")&"-"&TEXT(A2,"dd/mm/yyyy")

You need to break them down like so:
=DAY(A3)&"/"&MONTH(A3)&"/"&YEAR(A3)&"-"&DAY(A4)&"/"&MONTH(A4)&"/"&YEAR(A4)
I am assuming here your data start from cell A3

Assuming headings in row 1 and dates in rows 3 and 4 this will work:
=TEXT(A3,"dd/mm/yyyy")&TEXT(A4," - dd/mm/yyyy")
without having to concatenate " - "

Related

Excel cell text need to separate based on days and months

I have cell value with 115y300d which needs to be move to separate cell, however in few cell I have data like 10h30m, so it's mixed text.
What I want to do is value before "y" should go in Year Column "d" in Days, similar for h = hours and M in Minutes. Since it is not in similar format, I'm not able to do text to columns and other functions, and need your help.
You could use find() to do things like so:
=if(iferror(find("y",A2,1)>0,0),left(A2,find("y",A2,1)-1,"")
which will put the value before y into the cell or set it to blank.
Expand the idea to find d & y etc
One option could be:
Formula in B1:
=DROP(WRAPROWS(TEXTSPLIT(CONCAT(BYROW(A1:A5,LAMBDA(a,IF(RIGHT(a)="d",a&"hm","yd"&a)))),,{"y","d","h","m"},,""),4),-1)
If you hit CONCAT() limits, you can also do this by row (dragging):
=TEXTSPLIT(IF(RIGHT(A1)="d",A1&"hm","yd"&A1),{"y","d","h","m"},,,"")

Return Dates of Three Consecutive Values in a Row

I have a data file and I need to return the dates of when the value (MaxT) is greater than or equal to 30 (>=30) for 3 consecutive days.
Data File:
Date, MaxT
1872-03-01,31
1872-03-02,29
1872-03-03,37
1872-03-04,40
1872-03-05,22
1872-03-06,9
1872-03-07,28
1872-03-08,31
1872-03-09,35
1872-03-10,37
1872-03-11,44
1872-03-12,29
1872-03-13,35
1872-03-14,48
1872-03-15,33
1872-03-16,31
1872-03-17,38
1872-03-18,31
1872-03-19,42
1872-03-20,20
1872-03-21,24
1872-03-22,31
I have attempted to figure this out using the following code but, I do not think I'm even in the ballpark...
Attempted Code:
=SUMPRODUCT(--(FREQUENCY(IF(B2:B23>=30,ROW(B2:B23)),IF(B2:B23>=30,ROW(B2:B23)))=3))
I'm assuming that your data file consists of 2 columns Date and Max T. If they are delimited by commas, you need to split them to 2 different columns using Text to columns delimited by commas ,.
The Date should be in Column A and Max T in Column B.
Enter the below formula in cellC2 and drag down,
=IF(AND(B2>=30,B3>=30,B4>=30),"Consecutive Range","")
The starting of the consecutive range of values greater than 30 will be shown in the output as above. You could then use a filter of some other excel function like Index-Match to get the corresponding dates. Hope this helps.
Alright, I got it to work, but I'm not entirely sure how you would make it work without separating the formula into multiple cells.
One potential solution would be to write some of the formulas into a sheet that's in the background, place the final part of the formula in the front sheet and have it reference the "hidden" bits of the formula.
First, I wrote the data in columns... "Date" in Column A, "MaxT" in Column B.
The first part of the formula is written in cell D2:
=IF(B2>=30,B2,"")
The next part of the formula is written in cell E2:
=COUNT(D2:D4)
The last part of the formula is written in cell F2:
=IF(E2=3,A2&","&A3&","&A4,"")
The result of this formula, in column F, there are 7 cells that have three dates written in them, separated by a comma.
Note that you can make any character or string of text separate the three displayed dates by replacing the commas that are in-between the ampersand, quote text:
(&","&) can become (&"anything you want"&)
From here, auto-fill the formulas to the relevant cells.
EDIT:
One way to shorten the code is to add the COUNT formula into the last IF statement like this:
=IF(COUNT(D2:D4)=3,A9&","&A10&","&A11,"")
I do still think that the first IF statement will need to be separate from the rest of the formula, though.
EDIT #2
Here is the code in one single cell:
=IF(AND(B2>=30,B3>=30,B4>=30), A2&","&A3&","&A4,"")
Which will display three dates that are located within Column A, current row & the next two rows below it.
This code still produces 7 lines of results with the data that you've provided.

Identifying date in text file While date is incorrectly formatted

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

Concatenate and preserve format in excel

I have Excel table when one cell has 'text' formating and literally is A1 ABC: and second cell is custom formatting and literally is B1 2013-11-4
I need in the third cell C1 to concatenate both and get ABC:2013-11-4
I tried this: =concatenate(A1,A2) but it resulted in ABC:41582
My question: how could I concatenate A1 and B1 in order to keep custom formating of B1 cell?
Thanks
You have to set the date format within the concatenation. The concatenation is retrieving the value behind the cell.
Instead, you can easily specify the date format using TEXT(cell, format):
=CONCATENATE(TEXT(A1,"YYYY-M-D"),A2)
The YYYY, M, and D represent four digit year (2013), month (11), and day (4) respectively.
The Answer provided by grovesNL fixed my problem.
Ticket could be closed.

excel formula to combine 2 cells into 1 in specific format

I have 2 cells, one cell has just text A1 cell, text (hello) other cell B1 has a timestamp (3:55). I need to combine these cell to one with this format: hello#t=3m55s, or if timastamp is 1:12:11 format will be hello#t=1h12m11s. So cell A1 will change to this specific format base on B1 cell.
Thank you.
You could try this formula:
=A1&"#t="&IF(HOUR(B1)=0,"",HOUR(B1)&"h")&MINUTE(B1)&"m"&SECOND(B1)&"s"
The & concatenates each part together. However, if the timestamps are not correct for the mm:ss times, then it won't work.
EDIT: To deal with the issue of timestamps:
=A1&"#t="&IF(SECOND(B1)<>0,HOUR(B1)&"h"&MINUTE(B1)&"m"&SECOND(B1)&"s", HOUR(B1)&"m"&MINUTE(B1)&"s")
The issue with this is that it won't work for timestamps of the type "11:11:00" But I don't think there's much to be done, unless the string is first converted to text, which I could give some pointers on.

Resources