简体   繁体   中英

DataStudio and SQL change time format from numbers to hh:mm:ss

I want to change the metric format from float to HH:MM:SS in Datastudio (or SQL).

For Example:

Float HH:MM:SS
75 00:01:15
90 00:01:30
79.5 00:01:20

etc........

If your input seconds fit into 24 hours - so can be presented as a time type - use below

select format_timestamp('%T', timestamp_seconds(cast(seconds as int64))) time   

if applied to sample data in your question - output is

在此处输入图像描述

In case if input seconds exceed 24 hours - you can use below - which gives you a string representation in format of H*:MM:SS

select format('%i:%s',
    div(cast(seconds as int64), 3600),
    format_timestamp('%M:%S', timestamp_seconds(mod(cast(seconds as int64), 3600)))
  ) time

with output as

在此处输入图像描述

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