「MariaDB」 日時データからunix時間を取得する

環境
Windows10 64bit
MariaDB 10.6.4

書式
UNIX_TIMESTAMP( 日付 )
「UNIX_TIMESTAMP()」を使用して、日時データからunix時間を取得します。

操作例
1.SELECT UNIX_TIMESTAMP('2022-03-30’) result;
実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30') result;
+------------+
| result |
+------------+
| 1648566000 |
+------------+
1 row in set (0.000 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30') result; +------------+ | result | +------------+ | 1648566000 | +------------+ 1 row in set (0.000 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30') result;
+------------+
| result     |
+------------+
| 1648566000 |
+------------+
1 row in set (0.000 sec)

2.SELECT UNIX_TIMESTAMP('2022-03-30 00:00:01’) result;
実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30 00:00:01') result;
+------------+
| result |
+------------+
| 1648566001 |
+------------+
1 row in set (0.001 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30 00:00:01') result; +------------+ | result | +------------+ | 1648566001 | +------------+ 1 row in set (0.001 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2022-03-30 00:00:01') result;
+------------+
| result     |
+------------+
| 1648566001 |
+------------+
1 row in set (0.001 sec)

3.存在しない日付を指定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2000-20-00') result;
+--------+
| result |
+--------+
| NULL |
+--------+
1 row in set, 1 warning (0.150 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2000-20-00') result; +--------+ | result | +--------+ | NULL | +--------+ 1 row in set, 1 warning (0.150 sec)
MariaDB [(none)]> SELECT UNIX_TIMESTAMP('2000-20-00') result;
+--------+
| result |
+--------+
|   NULL |
+--------+
1 row in set, 1 warning (0.150 sec)

 

MariaDB

Posted by arkgame