在BigQuery中从Unix时间转换为YYYY-MM-DD

时间:2014-09-29 01:54:29

标签: google-bigquery

如果在BigQuery语法中有从UNIX时间转换为YYYY-MM-DD的功能或方法吗?

2 个答案:

答案 0 :(得分:3)

如果您已存储时间戳,则可以通过运行以下查询

来获取UTC格式
SELECT FORMAT_UTC_USEC((INTEGER(your_timestamp_field)+19800)*1000000)

答案 1 :(得分:1)

较新的“标准SQL”语法有a set of functions for timestamp operations。这包括timestamp_seconds,它将unixtime(以秒为单位 - 还有另一个函数,毫秒)转换为时间戳:

ClientConfig daxConfig = new ClientConfig()
    .withEndpoints(daxEndpoint).withRegion("us-west-2");
AmazonDaxClient client = new ClusterDaxClient(daxConfig);

如果要以特定方式格式化,可以将其转换为带format_timestamp的格式化字符串。例如,对于你的YYYY-MM-DD:

header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename=members.csv');

$q = 'SELECT * FROM `members` ORDER BY `Mid` ASC';
$q = mysqli_query($connection, $q);

while ($record = mysqli_fetch_assoc($q)) :

  echo $record['Member_Name'];

endwhile;