数据湖探索 DLI-unix_timestamp:示例代码

时间:2024-11-11 14:11:03

示例代码

返回1692149997。

select unix_timestamp('2023-08-16 09:39:57')

假设当前系统时间为2023-08-16 10:23:16,返回1692152596。

select unix_timestamp();

返回1692115200(即2023-08-16 00:00:00)。

select unix_timestamp("2023-08-16 10:56:45", "yyyy-MM-dd");
表数据示例
select timestamp1, unix_timestamp(timestamp1) as date1_unix_timestamp, timestamp2, unix_timestamp(datetime1) as date2_unix_timestamp, timestamp3, unix_timestamp(timestamp1) as date3_unix_timestamp from database_t;输出:
+------------+-------------------------+-----------------------+---------------------- --+------------------------------------+----------------------------+
| timestamp1| date1_unix_timestamp | timestamp2              | date2_unix_timestamp | timestamp3                                  | date3_unix_timestamp      |
+------------+-------------------------+-----------------------+-------------------------+------------------------------------+----------------------------+
| 2023-08-02 | 1690905600000           | 2023-08-02 11:09:14 | 1690945754793           | 2023-01-11 00:00:00.123456789 | 1673366400000                |
| 2023-08-03 | 1690992000000           | 2023-08-02 11:09:31 | 1690945771994           | 2023-02-11 00:00:00.123456789 | 1676044800000                |
| 2023-08-04 | 1691078400000           | 2023-08-02 11:09:41 | 1690945781270           | 2023-03-11 00:00:00.123456789 | 1678464000000                |
| 2023-08-05 | 1691164800000           | 2023-08-02 11:09:48 | 1690945788874           | 2023-04-11 00:00:00.123456789 | 1681142400000                |
| 2023-08-06 | 1691251200000           | 2023-08-02 11:09:59 | 1690945799099           | 2023-05-11 00:00:00.123456789 | 1683734400000                |
+------------+-------------------------+-----------------------+--------------------------+-----------------------------------+----------------------------+
support.huaweicloud.com/sqlref-spark-dli/dli_spark_unix_timestamp.html