68

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.

0

6 Answers 6

80

Use the TEXT function.

=TEXT(<cellReference>, "mm-dd-yyyy")

e.g.,

=TEXT(A1, "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
    Commented Nov 29, 2016 at 6:39
  • That's ... a completely different question from what you asked lol. Like not even close.
    – Alexander
    Commented 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
    Commented 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
    Commented Nov 29, 2016 at 7:00
56

Use the TEXTJOIN function. Give it:

  • delimiter parameter: empty string ""
  • ignore_empty parameter: TRUE
  • text1 parameter: the referenced cell (e.g., A1)
  • provide no other parameters

e.g.,

=TEXTJOIN("",TRUE,A1)
3
  • 2
    A nasty trick, but far the best answer! (I've Tried all others, but none really worked well) Commented 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
    Commented Jul 15, 2018 at 21:54
  • In my case this was actually the best solution, because in CONCAT() with date cell was rendering it as a number and I needed it as a text, so this worked perfectly, thanks! Commented Jan 1 at 6:39
19

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

enter image description here

This cell is now a string.

10
  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. Commented 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 you have read our privacy policy.

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