关闭

mysql---日期和时间函数

162人阅读 评论(0) 收藏 举报
分类:

获取当前时间戳

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                                |
+----------------------------------------------------+
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48080次
    • 积分:1555
    • 等级:
    • 排名:千里之外
    • 原创:110篇
    • 转载:10篇
    • 译文:0篇
    • 评论:1条
    文章分类