mysql---日期和时间函数

获取当前时间戳

select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
|       1436250154 |
+------------------+

获取当前小时

select current_time();
+----------------+
| current_time() |
+----------------+
| 14:23:16       |
+----------------+

获取当前完整时间

select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2015-07-07 14:26:32 |
+---------------------+

获取当前日期

select current_date();
+----------------+
| current_date() |
+----------------+
| 2015-07-07     |
+----------------+

将日期转换成时间戳

 select unix_timestamp("2001-01-01");

+------------------------------+
| unix_timestamp("2001-01-01") |
+------------------------------+
|                    978278400 |
+------------------------------+

时间戳转日期

select from_unixtime(unix_timestamp(), "%Y-%m-%d %H:%i:%m");
+------------------------------------------------------+
| from_unixtime(unix_timestamp(), "%Y-%m-%d %H:%i:%m") |
+------------------------------------------------------+
| 2015-07-07 14:33:07                                  |
+------------------------------------------------------+

当前日期前一年月日时分秒

select date_sub("2015-07-07 14:33:33", interval 1 year/month/day/hour/minute/second);
+----------------------------------------------------+
| date_sub("2015-07-07 14:33:33", interval 1 minute) |
+----------------------------------------------------+
| 2015-07-07 14:32:33                                |
+----------------------------------------------------+

当前日期后一年月日时分秒

select date_sub("2015-07-07 14:33:33", interval 1 year/month/day/hour/minute/second);
+----------------------------------------------------+
| date_sub("2015-07-07 14:33:33", interval  -1 minute) |
+----------------------------------------------------+
| 2015-07-07 14:34:33                                |
+----------------------------------------------------+
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xing_____/article/details/46789339
个人分类: mysql
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

mysql---日期和时间函数

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭