I have two cells in Excel. one has a string and the other one has a date. in the third cell I want to put the date and the string together. For example:
A1 = "This "
A2 = "03/03/1982"
I want A3 to be:
This 03/03/1982
when I try to put this in the A3 formula: = A1 & A2 it returns some funny numerical value for the date and does not give me the literal date.
Don't know if it's the best way but I'd do this:
=A1 & TEXT(A2,"mm/dd/yyyy")
That should format your date into your desired string.
Edit: That funny number you saw is the number of days between December 31st 1899 and your date. That's how Excel stores dates.
This is the numerical representation of the date. The thing you get when referring to dates from formulas like that.
You'll have to do:
= A1 & TEXT(A2, "mm/dd/yyyy")
The biggest problem here is that the format specifier is locale-dependent. It will not work/produce not what expected if the file is opened with a differently localized Excel.
Now, you could have a user-defined function:
public function AsDisplayed(byval c as range) as string
AsDisplayed = c.Text
end function
and then
= A1 & AsDisplayed(A2)
But then there's a bug (feature?) in Excel because of which the .Text property is suddenly not available during certain stages of the computation cycle, and your formulas display #VALUE instead of what they should.
That is, it's bad either way.
Another approach
=CONCATENATE("Age as of ", TEXT(TODAY(),"dd-mmm-yyyy"))
This will return
Age as of 06-Aug-2013
Thanks for the solution !
It works, but in a french Excel environment, you should apply something like
TEXTE(F2;"jj/mm/aaaa")
to get the date preserved as it is displayed in F2 cell, after concatenation.
Best Regards
You can do it this simple way :
A1 = Mahi
A2 = NULL(blank)
Select A2 Right click on cell --> Format cells --> change to TEXT
Then put the date in A2 (A2 =31/07/1990)
Then concatenate it will work. No need of any formulae.
=CONCATENATE(A1,A2)
mahi31/07/1990
(This works on the empty cells ie.,Before entering the DATE value to cell you need to make it as TEXT).
I found that for this situation, the simplest solution is to define a Custom number format for the cell containing the date. The format in this case should be:
"This:" mm/dd/yyyy
To set this format:
Right click on the cell
Select Format Cell
Select Number tab (should be displayed by default)
Pick Custom from the Category list
Specify the format in the "Type" field
Press OK
Note: If you really want the preceding text to be picked from a cell, this solution will not work as described.
Related
So I have this data directly copy/paste from iTunes :
Excel have "XX:XX:00" format which is "hh:mm:ss" but as you can imagine, it is more like "mm:ss:00". Musics are not hours long !
As it's not a direct cell format problem, I couldn't find easily the answer on internet. I need sometihng to put the 2 "00" at the start (in order to have "00:mm:ss")
EDIT : It was a cell format comprehension problem.
You can just divide the cell value to 60 like so
and then choose custom format for that cell like this
Format the cell with the time (C1) as "General". If it retains its value, like 11:42, then convert it with =TimeValue(C1) and format the cell as Custom mm:ss
If it changes to something like 0.4875 then convert it with =C1/60 and format the result as Custom mm:ss
This formula should work:
="00:" & MID(TEXT(A1,"h:mm:ss"),SEARCH(":",TEXT(A1,"h:mm:ss"))+1,3) & RIGHT(TEXT(A1,"h:mm:ss"),2)
The important element is to convert the time into a text string.
Change A1 to the first cell of Duration (Duree) & copy the formula downward
Then, you can copy the result and paste it as values
Edit: you can also use just the right function:
="00:"&RIGHT(TEXT(A1,"h:mm:ss"),LEN(TEXT(A1,"h:mm:ss"))-SEARCH(":",TEXT(A1,"h:mm:ss")))
I have two cells in my excel sheet, where I compare them against each other.
Now, it's a long sheet, and I have formatted all the date cells to "Short Date". However, some dates are entered like below:
'02-02-2015
And others are entered without the ':
02-02-2015
Now, the problem is when I compare those two dates above - it doesn't give me the correct result, because of the " ' "
How can I "strip" all the date fields to not use the apostrophe in front?
Thanks.
You can try converting both to one type when comparing them
, e.g. TEXT
Example
=IF(TEXT(A1;)=TEXT(B1;);1;0)
Use Replace
Example:
Dim D As Date: D = Replace("'20-01-2015", "'", "")
With data in column A, in B1 enter:
=IF(LEFT(A1,1)="'",MID(A1,2,9999),A1)
and copy down. For example:
I have a cell with the contents of 41316. I have it formatted as 20130211.
I need another cell to reference that value, but in the cell have it showing as 20130211 not 41316 formatted.
This maybe an easy one, but for some reason it has me running in circles.
Thanks in advance for all responses.
Excel by default copies the format from a cell formatted as a date to a cell which references it. It sounds in your case that Excel hasn't done that for you, so you just need to format the new cell with your special format : paintbrush tool or Edit..Copy, Edit..Past Special..Formats or Format..Number..Custom and select your format, which will be at the bottom of a long list.
If a string is ok instead of a number, you can decompose that date in parts and concatenate:
Being A1 the cell containing the value:
= Year(A1) & "/" & Month(A1) & "/" & Day(A1)
The "&" symbol concatenates text. The slashes are optional if you want them separated by slashes.
if your cell referencing 20130211 is 'A1' put =TEXT(A1,"####") in your calculation cell. If you do it this way then it will still read as a number and not a string
I know excel "programming" is not very popular among fellow programmers, however I've been struggling to get this right and management is on my neck..
I have the custom validation on excel :
=AND(LEN(AV15)=10,((VALUE(LEFT(AV15,2)))<=31),NOT(ISERROR(VALUE(LEFT(AV15,2)))),MID(AV15,3,1)="/",((VALUE(MID(AV15,4,2)))<=12),NOT(ISERROR(VALUE(MID(AV15,4,2)))),MID(AV15,6,1)="/",((VALUE(RIGHT(AV15,4)))<=2100),NOT(ISERROR(VALUE(RIGHT(AV15,4)))))
The validation above is supposed to accept any valid date in the format:
dd/mm/yyyy
It seems to be working partially, but somehow it wont accept a day lower than "12", example:
14/12/2010 -->accepted
13/10/2010 -->accepted
25/10/2010 -->accepted
12/10/2010 -->gives error
At first glance one would thing that the ((VALUE(MID(AV15,4,2)))<=12) is causing this behavior, but I changed it to 31 and I still get the error, I need the validation to admit inputs in :
nn/nn/nnnn
where "n" is a number, i don't care if they input 99/99/9999 I can check that later on vba code, but the input has to specifically have the 10 characters.
any help would be highly appreciated
I put your formula in and when you put a ' before the date it works just fine. What is going on is that when you put any value below 13 as the day it evaluates the date like a date, which is stored as a number in Excel. When you have above 13 it evaluates as a string. So what you need to do is format the cell to Text format. Then it should work just fine.
To see if the following works, put the date value in A1
A1 -> '14/12/2010
Put the following formulas as mentioned below
B1 -> =MID(A1,3,1) = "/"
C1 -> =MID(A1,6,1) = "/"
D1 -> =IFERROR(AND(VALUE(MID(A1,4,2)) >= 1, VALUE(MID(A1,4,2)) <= 12), FALSE)
E1 -> =AND(VALUE(RIGHT(A1,4))>=2000,AND(VALUE(RIGHT(A1,4))<=2100))
F1 -> =AND(B1,C1,D1, E1)
The formulas above are splitted and you will have to combine them (as it is done in cell F1).
Hope that helps.
EDIT: The combined formula for validation will be (note that I have used A1 as the cell)
=AND(MID(A1,3,1) = "/", MID(A1,6,1) = "/", IFERROR(AND(VALUE(MID(A1,4,2)) >= 1, VALUE(MID(A1,4,2)) <= 12), FALSE), AND(VALUE(RIGHT(A1,4))>=2000,AND(VALUE(RIGHT(A1,4))<=2100)))
Can you not simply choose the correct format in the cell?
Right click in the cell and select 'Format Cell'
Select 'Custom' from the left side navigation
In the 'Type:' box enter this: dd/mm/yyyy
Excel appears to be recognising values such as 10/12/2010 as dates and storing them internally in a different format, such as the number of days since Jan 1 1900 or suchlike. It happens that when you use LEFT, MID and RIGHT on these date values, Excel doesn't do the conversion back from its internal format. In particular, I put 10/12/2010 in cell A1 and =LEFT(A1,10) in cell B1. Cell B1 then showed me the value 40522. (I'm in the UK and using Excel 2010 Starter. You may get different values in other locales or with other versions of Excel.)
Try replacing all occurrences of AV15 in your formula with TEXT(AV15, "DD/MM/YYYY"). Alternatively, put =TEXT(AV15, "DD/MM/YYYY") in another cell and use this other cell in your formula in place of AV15.
If you aren't wary of VBA, then what about a simple UDF?
Public Function DateFormat(rng As Range)
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "\d\d/\d\d/\d\d\d\d"
test = regEx.Execute(rng.Value).Count > 0
End Function
This should return true if the value of a cell matches nn/nn/nnnn where n is any number.
Then you could simply say =DateFormat(AV15)
In a cell in Excel sheet I have a Date value like:
01/01/2010 14:30:00
I want to convert that Date to Text and also want the Text to look exactly like Date. So a Date value of 01/01/2010 14:30:00 should look like 01/01/2010 14:30:00 but internally it should be Text.
How can I do that in Excel?
=TEXT(A1,"DD/MM/YYYY hh:mm:ss")
(24 hour time)
=TEXT(A1,"DD/MM/YYYY hh:mm:ss AM/PM")
(standard time)
Here is a VBA approach:
Sub change()
toText Sheets(1).Range("A1:F20")
End Sub
Sub toText(target As Range)
Dim cell As Range
For Each cell In target
cell.Value = cell.Text
cell.NumberFormat = "#"
Next cell
End Sub
If you are looking for a solution without programming, the Question should be moved to SuperUser.
Here's another option. Use Excel's built in 'Text to Columns' wizard. It's found under the Data tab in Excel 2007.
If you have one column selected, the defaults for file type and delimiters should work, then it prompts you to change the data format of the column. Choosing text forces it to text format, to make sure that it's not stored as a date.
In some contexts using a ' character beforehand will work, but if you save to CSV and load again this is impossible.
'01/01/2010 14:30:00
Couldnt get the TEXT() formula to work
Easiest solution was to copy paste into Notepad and back into Excel with the column set to Text before pasting back
Or you can do the same with a formula like this
=DAY(A2)&"/"&MONTH(A2)&"/"&YEAR(A2)& " "&HOUR(B2)&":"&MINUTE(B2)&":"&SECOND(B2)
I have no idea about the year of publication of the question; it might be old now. So, I expect my answer to be more of a reference for future similar questions after my post.
I don't know if anybody out there has already given an answer similar to the one I am about to give, which might result -I think- being the simplest, most direct and most effective: If someone has already given it, I apologize, but I haven't seen it. Here, my answer using CStr instead of TEXT:
Asuming cell A1 contains a date, and using VBA code:
Dim strDate As String
'Convert to string the value contained in A1 (a date)
strDate = CStr([A1].Value)
You can, thereafter, manipulate it as any ordinary string using string functions (MID, LEFT, RIGHT, LEN, CONCATENATE (&), etc.)
If you are not using programming then do the following
(1) select the column
(2) right click and select Format Cells
(3) Select "Custom"
(4) Just Under "Type:" type dd/mm/yyyy hh:mm:ss
In Excel 2010, marg's answer only worked for some of the data I had in my spreadsheet (it was imported). The following solution worked on all data.
Sub change()
toText Selection
End Sub
Sub toText(target As range)
Dim cell As range
Dim txt As String
For Each cell In target
txt = cell.text
cell.NumberFormat = "#"
cell.Value2 = txt
Next cell
End Sub
As Text is localized it will break when trying you try to share your files over diffrent cultures. ÅÅÅÅ-MM-DD might work perfectly in sweden, is US, Germany or israel it will turn to shit.
The reasonable solution would be that english was accepted everywhere, but it's not.
Basically DON'T EVER use text as intended to format dates.
Here is how to create the date in ISO format. TEXT is used to ensure leading
=YEAR(A1)&"-"&TEXT(MONTH(A1);"00")&"-"&TEXT(DAY(A1);"00")
If you want it backwards, sideways or whatever, just change it.
https://www.reddit.com/r/ISO8601/comments/enhlp6/logic_of_the_different_date_time_systems_with/
The selected answer did not work for me as Excel was still not converting the text to date. Here is my solution.
Say that in the first column, A, you have data of the type 2016/03/25 21:20:00 but is stored as text. Then in column B write =DATEVALUE(A1) and in column C write =TIMEVALUE(A1).
Then in column D do =B1+C1 to add the numerical formats of the date and time.
Finally, copy the values from D into column E by right clicking in column E and select Paste Special -> Paste as Values.
Highlight the numerical values in column E and change the data type to date - I prefer using a custom date of the form YYYY-MM-DD HH:MM:SS.