mysql date函数
mysql中date函数是什么,怎么使用呢?不知道的小伙伴来看看小编今天的分享吧!
1、date函数简介
MySQL数据库Date()日期函数,用于MySQL数据库查询当前日期,时间。
2、用法
获取当前时间
MySQL> select current_tistamp();
+---------------------+
| current_tistamp() |
+---------------------+
| 2010-01-18 21:24:37 |
+---------------------+
1 row in set (0.00 sec)
MySQL> select current_date();
+----------------+
| current_date() |
+----------------+
| 2010-01-18 |
+----------------+
1 row in set (0.00 sec)
MySQL> select current_ti();
+----------------+
| current_ti() |
+----------------+
| 21:24:46 |
+----------------+
1 row in set (0.00 sec)
Unix时间
MySQL> select unix_tistamp();
+------------------+
| unix_tistamp() |
+------------------+
| 1263821184 |
+------------------+
1 row in set (0.00 sec)
MySQL> select from_unixti(1263821182);
+---------------------------+
| from_unixti(1263821182) |
+---------------------------+
| 2010-01-18 21:26:22 |
+---------------------------+
1 row in set (0.00 sec)
时间前后
MySQL> select date_add(current_tistamp, interval 1 day);
+---------------------------------------------+
| date_add(current_tistamp, interval 1 day) |
+---------------------------------------------+
| 2010-01-19 21:27:53 |
+---------------------------------------------+
1 row in set (0.00 sec)
MySQL> select date_add(current_ti, interval 1 day);
+----------------------------------------+
| date_add(current_ti, interval 1 day) |
+----------------------------------------+
| NULL |
+----------------------------------------+
1 row in set, 1 warning (0.00 sec)
MySQL> select date_add(current_date, interval 1 day);
+----------------------------------------+
| date_add(current_date, interval 1 day) |
+----------------------------------------+
| 2010-01-19 |
+----------------------------------------+
1 row in set (0.00 sec)
MySQL> select date_sub(current_tistamp, interval 1 day);
+---------------------------------------------+
| date_sub(current_tistamp, interval 1 day) |
+---------------------------------------------+
| 2010-01-17 21:28:41 |
+---------------------------------------------+
1 row in set (0.00 sec)
MySQL> select date_sub(current_date, interval 1 day);
+----------------------------------------+
| date_sub(current_date, interval 1 day) |
+----------------------------------------+
| 2010-01-17 |
+----------------------------------------+
1 row in set (0.00 sec)
MySQL> select date_sub(current_ti, interval 1 day);
+----------------------------------------+
| date_sub(current_ti, interval 1 day) |
+----------------------------------------+
| NULL |
+----------------------------------------+
1 row in set, 1 warning (0.00 sec)
时间间隔
MySQL> select datediff('2010-01-18','2010-01-17');
+-------------------------------------+
| datediff('2010-01-18','2010-01-17') |
+-------------------------------------+
| 1 |
+-------------------------------------+
1 row in set (0.00 sec)
MySQL> select tidiff('2010-01-18 12:00','2010-01-17 11:00');
+-------------------------------------------------+
| tidiff('2010-01-18 12:00','2010-01-17 11:00') |
+-------------------------------------------------+
| 25:00:00 |
+-------------------------------------------------+
1 row in set (0.00 sec)
时间转换
MySQL> select ti_to_sec('25:00:00');
+-------------------------+
| ti_to_sec('25:00:00') |
+-------------------------+
| 90000 |
+-------------------------+
1 row in set (0.00 sec)
MySQL> select sec_to_ti(90000);
+--------------------+
| sec_to_ti(90000) |
+--------------------+
| 25:00:00 |
+--------------------+
1 row in set (0.00 sec)
以上就是小编今天的分享了,希望可以帮助到大家。
生活小妙招
- 杭州市小客车总量调控管理暂行规定
- 个人所得税退税的条件和标准 下载个人所得税
- 江苏省南通市通州区天气 江苏省南通通州区天气
- 夫妻有按揭的房子离婚怎么办 夫妻有按揭的房子
- 山东省青岛市市北区天气 山东省青岛市市北区天
- 什么财产离婚后不用分割 什么财产离婚后不用分
- 工伤认定必须满足三个条件 工伤认定申请必须满
- 家暴出轨不受离婚冷静期限制 家暴不适用离婚冷
- 武夷山一周天气预报 武夷山一周天气预报15天准
- 怎么与孩子沟通最有效方法 怎么与孩子沟通的技
- 女方提出离婚财产怎么分割 女方提出离婚财产怎
- 华东五市天气预报 华东五市的天气
- 深圳车辆违章记录查询 深圳车辆违章记录查询
- 老公铁了心要离婚还能挽回吗 老公铁了心离婚的
- 怎么计算工伤十级的赔偿金 工伤十级赔偿计算公
- 武汉天气预报15天气报 武汉天气预报15天