55

I am trying to figure out how to convert a date into a string in a google sheet.

I have one date field that has varying formats. I want create another column that's literally just the same but as a text. For example, if I had the following data

date       date_as_string
12-05-2016 '12-05-2016
12/5/2016  '12/5/2016
2016-12-10 '2016-12-10

Where the ' is just to denote that it is a string note a date.

1
  • If your question has een answered, please mark one of the answered as accepted.
    – Alexander
    Nov 20, 2019 at 17:54

6 Answers 6

69

You can use the TEXT function.

=Text(cellReference, "mm-dd-yyyy")
4
  • Oh sorry, I realize I phrased my question very poorly. What I meant was I have a date field. It might have the format mm-dd-yyyy or it might have a format mm/dd/yyyy. I would like to create a new column that is literally just the same but as text with the same format. I'll update my original question as appropriate.
    – Vincent
    Nov 29, 2016 at 6:39
  • That's ... a completely different question from what you asked lol. Like not even close.
    – Alexander
    Nov 29, 2016 at 6:40
  • Right. Sorry. I remember trying to use the TEXT formula, but it seems like you can't just specify using the same format.
    – Vincent
    Nov 29, 2016 at 6:43
  • TEXT is still the way to do this, but you need a way of determining the format on a string per string basis.
    – Alexander
    Nov 29, 2016 at 7:00
53

Use the TEXTJOIN function. Give an empty delimiter, TRUE for the ignore empty, the referenced cell as text1, and don't supply anything for text2.

=TEXTJOIN("",TRUE,A1)

Done.

2
  • 2
    A nasty trick, but far the best answer! (I've Tried all others, but none really worked well) Jul 14, 2018 at 16:16
  • 5
    @Richard I think learning Perl taught me to look for the 'nasty' tricks which make life easier in the end.
    – Chindraba
    Jul 15, 2018 at 21:54
17

=TEXT(now(),"yyyy-MM-dd hh:mm:ss")

enter image description here

This cell is now a string.

9
  1. copy the column to another column
  2. select the copied column
  3. go to menu 'Format' --> 'Number' --> 'Plain text'
1
  • I used this with my Google spreadsheet. The dates look 1 on on the sheet but but reading them comes up with something different. Just select the rows you want to fix and the do # 3 above. Sep 26, 2018 at 19:23
5

to concatenate text to date you can do this:

=CONCATENATE("today is: ", TEXT(HOY(), "dd-mm-yyyy"))

4

there's no way to detect the format of dates in google sheets. But you may use getDisplayValues property. Paste this code into script editor:

function repeatAsText(A1Notation, sheet) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  if (sheet) { sheet = ss.getSheetByName(sheet); }
  else { sheet = ss.getActiveSheet(); }
  var range = sheet.getRange(A1Notation);
 
  return range.getDisplayValues();
}

and then use it as ususl formula:

=repeatAsText("A1:A3")

enter image description here

A1Notation -- string like "A1" or "B3:AD15".

sheet -- name of sheet, like "Sheet1". It is optional, use ActiveSheet if omitted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.