mysql date函数

mysql中date函数是什么,怎么使用呢?不知道的小伙伴来看看小编今天的分享吧!

1、date函数简介:

MySQL数据库Date()日期函数,用于MySQL数据库查询当前日期,时间。

2、用法:

获取当前时间:

MySQL>selectcurrent_timestamp();

+---------------------+

|current_timestamp()|

+---------------------+

|2010-01-1821:24:37|

+---------------------+

1rowinset(0.00sec)

MySQL>selectcurrent_date();

+----------------+

|current_date()|

+----------------+

|2010-01-18|

+----------------+

1rowinset(0.00sec)

MySQL>selectcurrent_time();

+----------------+

|current_time()|

+----------------+

|21:24:46|

+----------------+

1rowinset(0.00sec)

Unix时间:

MySQL>selectunix_timestamp();

+------------------+

|unix_timestamp()|

+------------------+

|1263821184|

+------------------+

1rowinset(0.00sec)

MySQL>selectfrom_unixtime(1263821182);

+---------------------------+

|from_unixtime(1263821182)|

+---------------------------+

|2010-01-1821:26:22|

+---------------------------+

1rowinset(0.00sec)

时间前后:

MySQL>selectdate_add(current_timestamp,interval1day);

+---------------------------------------------+

|date_add(current_timestamp,interval1day)|

+---------------------------------------------+

|2010-01-1921:27:53|

+---------------------------------------------+

1rowinset(0.00sec)

MySQL>selectdate_add(current_time,interval1day);

+----------------------------------------+

|date_add(current_time,interval1day)|

+----------------------------------------+

|NULL|

+----------------------------------------+

1rowinset,1warning(0.00sec)

MySQL>selectdate_add(current_date,interval1day);

+----------------------------------------+

|date_add(current_date,interval1day)|

+----------------------------------------+

|2010-01-19|

+----------------------------------------+

1rowinset(0.00sec)

MySQL>selectdate_sub(current_timestamp,interval1day);

+---------------------------------------------+

|date_sub(current_timestamp,interval1day)|

+---------------------------------------------+

|2010-01-1721:28:41|

+---------------------------------------------+

1rowinset(0.00sec)

MySQL>selectdate_sub(current_date,interval1day);

+----------------------------------------+

|date_sub(current_date,interval1day)|

+----------------------------------------+

|2010-01-17|

+----------------------------------------+

1rowinset(0.00sec)

MySQL>selectdate_sub(current_time,interval1day);

+----------------------------------------+

|date_sub(current_time,interval1day)|

+----------------------------------------+

|NULL|

+----------------------------------------+

1rowinset,1warning(0.00sec)

时间间隔:

MySQL>selectdatediff('2010-01-18','2010-01-17');

+-------------------------------------+

|datediff('2010-01-18','2010-01-17')|

+-------------------------------------+

|1|

+-------------------------------------+

1rowinset(0.00sec)

MySQL>selecttimediff('2010-01-1812:00','2010-01-1711:00');

+-------------------------------------------------+

|timediff('2010-01-1812:00','2010-01-1711:00')|

+-------------------------------------------------+

|25:00:00|

+-------------------------------------------------+

1rowinset(0.00sec)

时间转换:

MySQL>selecttime_to_sec('25:00:00');

+-------------------------+

|time_to_sec('25:00:00')|

+-------------------------+

|90000|

+-------------------------+

1rowinset(0.00sec)

MySQL>selectsec_to_time(90000);

+--------------------+

|sec_to_time(90000)|

+--------------------+

|25:00:00|

+--------------------+

1rowinset(0.00sec)

以上就是小编今天的分享了,希望可以帮助到大家。

标签:date函数 mysql

免责声明:本内容来自橡树街平台创作者或收集于互联网公开资源,不代表橡树街网的观点和立场。如有侵权内容,请联系我们删除。联系邮箱:ihuangque@qq.com
相关推荐
  • mysql时间格式转换
    mysql时间格式转换
    08-05
  • mysql 加索引
    mysql 加索引
    08-05
  • mysql datetime格式
    mysql datetime格式
    08-05
  • mysql ocp认证考试费用
    mysql ocp认证考试费用
    08-05
  • mysql distinct用法
    mysql distinct用法
    08-05
  • mysql 删除用户
    mysql 删除用户
    08-05
  • mysqldump导出数据库
    mysqldump导出数据库
    08-05
  • mysql官网怎样下载64位安装版
    mysql官网怎样下载64位安装版
    08-05
  • mysql 替换函数
    mysql 替换函数
    08-05
  • mysql date_sub
    mysql date_sub
    08-05