mysql date函数
mysql中date函数是什么,怎么使用呢?不知道的小伙伴来看看小编今天的分享吧!
1、date函数简介:
MySQL数据库Date()日期函数,用于MySQL数据库查询当前日期,时间。
2、用法:
获取当前时间:
MySQL> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 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_time();
+----------------+
| current_time() |
+----------------+
| 21:24:46 |
+----------------+
1 row in set (0.00 sec)
Unix时间:
MySQL> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1263821184 |
+------------------+
1 row in set (0.00 sec)
MySQL> select from_unixtime(1263821182);
+---------------------------+
| from_unixtime(1263821182) |
+---------------------------+
| 2010-01-18 21:26:22 |
+---------------------------+
1 row in set (0.00 sec)
时间前后:
MySQL> select date_add(current_timestamp, interval 1 day);
+---------------------------------------------+
| date_add(current_timestamp, interval 1 day) |
+---------------------------------------------+
| 2010-01-19 21:27:53 |
+---------------------------------------------+
1 row in set (0.00 sec)
MySQL> select date_add(current_time, interval 1 day);
+----------------------------------------+
| date_add(current_time, 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_timestamp, interval 1 day);
+---------------------------------------------+
| date_sub(current_timestamp, 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_time, interval 1 day);
+----------------------------------------+
| date_sub(current_time, 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 timediff('2010-01-18 12:00','2010-01-17 11:00');
+-------------------------------------------------+
| timediff('2010-01-18 12:00','2010-01-17 11:00') |
+-------------------------------------------------+
| 25:00:00 |
+-------------------------------------------------+
1 row in set (0.00 sec)
时间转换:
MySQL> select time_to_sec('25:00:00');
+-------------------------+
| time_to_sec('25:00:00') |
+-------------------------+
| 90000 |
+-------------------------+
1 row in set (0.00 sec)
MySQL> select sec_to_time(90000);
+--------------------+
| sec_to_time(90000) |
+--------------------+
| 25:00:00 |
+--------------------+
1 row in set (0.00 sec)
-
皮卡车办营运证多少钱?
1200到1300不等:1、据说现在的政策是将皮卡归为非营运车辆了,建议你咨询以下当地运管处,以前皮卡是默认的营运车辆,现在改了;2、营运和非营运皮卡车是有相关规定可以区分的;...
问答查看全文>> -
福睿斯的轮胎多久要前后换?
福睿斯的轮胎6万至12万公里要前后换,轮胎是在各种车辆或机械上装配的接地滚动的圆环形弹性橡胶制品,其通常安装在金属轮辋上,能支撑车身、缓冲外界冲击、实现与路面的接触并保证车辆的...
问答查看全文>> -
简单的句子说说心情 立夏句子说说
1、让立夏的烈日晒伤烦恼,让立夏的微风吹跑了糟糕,让立夏的小雨冲刷掉焦躁,让立夏的短信吞并了苦恼。立夏到,立夏好,立夏祝福我先到,愿您快乐又逍遥!2、大清早,蝉就高声大叫,告诉...
说说查看全文>>
推荐
- 1英文文献引用格式479
- 2途观x的车身尺寸多大124
- 3单边转向不足的原因的主要作用是什么?477
- 4别克英朗水箱怎么拆卸?259
- 5卡罗拉方向盘沉重的原因是什么?481
- 6汽车轮廓改装可以年检吗?406
- 7祝妈妈生日祝福语简短精辟322
- 8大众高尔夫6的火花塞多久换一次?208