[英]How to convert time format to a number format (Google Sheets/Data Studio)
I want to convert the numbers in ColA to normal numbers, like the ones I have in ColB.我想将 ColA 中的数字转换为普通数字,就像我在 ColB 中的数字一样。 The one in ColA currently are in this format: 00:56:00.000.
ColA 中的当前格式为:00:56:00.000。 I initially started out with a time length, that I then converted to seconds (what's currently in ColA).
我最初以时间长度开始,然后将其转换为秒数(目前在 ColA 中)。 I need to convert them back into a single number to import into Data Studio so it can read it as time.
我需要将它们转换回单个数字以导入 Data Studio,以便它可以按时间读取。 If I try to change the formatting to a number it comes up as a decimal, how can I change the format to a number?
如果我尝试将格式更改为小数形式的数字,如何将格式更改为数字? Or can I do it in Data Studio?
或者我可以在 Data Studio 中完成吗?
https://docs.google.com/spreadsheets/d/1xaAfc6hcFJJ1JsPfrx9Ly3usfljuzELT80UsgSxcNM8/edit#gid=0 https://docs.google.com/spreadsheets/d/1xaAfc6hcFJJ1JsPfrx9Ly3usfljuzELT80UsgSxcNM8/edit#gid=0
Try this on col B3
on Google Sheets while A3:A
is converted into number format (in decimals):当
A3:A
转换为数字格式(小数)时,在 Google 表格的B3
列上尝试此操作:
=Arrayformula((A3:A*3600)*24)
Output: Output:
Explanation:解释:
This is just an observation, but it seems that Google Data Studio strictly follows the formatting of the cell values.这只是一个观察,但 Google Data Studio 似乎严格遵循单元格值的格式。 If you want to read the seconds as integers, a few arithmetic operations was performed to convert the number formatting of duration as such presented above.
如果您想将秒数读取为整数,则执行一些算术运算以转换上述持续时间的数字格式。
Apps Script (use this if removing helper column B): Apps 脚本(如果删除辅助列 B,则使用此脚本):
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getRange('A3:A').getValues();
Logger.log(data);
var second = 3600;
var hour = 24;
var output = data.map(x => [x[0] * second * hour]);
ss.getActiveSheet().getRange(3, 1, output.length, output[0].length).setValues(output);
}
Output: Output:
Change format to seconds only.将格式更改为仅秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.