How to convert a date to a string in Google Sheet

后端 未结 6 2118
轮回少年
轮回少年 2021-02-03 20:13

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 lit

6条回答
  •  孤街浪徒
    2021-02-03 20:27

    I don't understand why you need this. Just figured out that 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")

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

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

提交回复
热议问题