要将日期转换为UNIX时间戳,请在MySQL中使用UNIX_TIMESTAMP()-
mysql> create table DemoTable1997 ( DueDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1997 values('2018-10-11'); mysql> insert into DemoTable1997 values('2019-12-21'); mysql> insert into DemoTable1997 values('2017-01-31');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1997;
这将产生以下输出-
+------------+ | DueDate | +------------+ | 2018-10-11 | | 2019-12-21 | | 2017-01-31 | +------------+ 3 rows in set (0.00 sec)
这是将YYYY-MM-DD转换为unix时间戳的查询-
mysql> select unix_timestamp(cast(DueDate as date)) as Result from DemoTable1997;
这将产生以下输出-
+------------+ | Result | +------------+ | 1539196200 | | 1576866600 | | 1485801000 | +------------+ 3 rows in set (0.00 sec)