简体   繁体   中英

How can I getValue() of specific number of characters in a cell/range

I am trying to find a way to only getValue() of a specific number of characters in a cell/range. For example:

I'm looking at this data in a cell= 4/17/2019 10:15:48 I want to take that data and compare it to another data to determine if it is today or not. The issue is I don't care if it's 10:15:48. I just want to know if it was done on 4/17/2019.

Is it possible to getValue of the cell, but only take the first 9 characters instead of the entire cell data.

Thank you for your help in advance.

For example, it supposes that the value of 4/17/2019 10:15:48 is put in a cell "A1" of the active sheet. In this case, how about the following sample script? I thought that when the value retrieved by getValues() is a date object, the result you want cannot be retrieved. So in this modification, I used getDisplayValue() for retrieving the value.

Sample script:

var sheet = SpreadsheetApp.getActiveSheet();
var value = sheet.getRange("A1").getDisplayValue();
var res = value.substr(0, 9);
Logger.log(res)

Note:

  • If you want to retrieve values from several cells, you can also use getDisplayValues() .

References:

If I misunderstood your question, I apologize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM