以下的文章主要介绍的是MySQL Date函数的实际应用其中包括如何获取当前时间的具体操作,Unix时间的具体应用,时间前后、时间间隔与时间转换的实际内容描述,以下就是文章的主要内容。

MySQL Date函数 1、获取当前时间

  1. MySQL> select current_timestamp();
  2. +---------------------+
  3. | current_timestamp() |
  4. +---------------------+
  5. | 2010-01-18 21:24:37 |
  6. +---------------------+
  7. 1 row in set (0.00 sec)
  8. MySQL> select current_date();
  9. +----------------+
  10. | current_date() |
  11. +----------------+
  12. | 2010-01-18 |
  13. +----------------+
  14. 1 row in set (0.00 sec)
  15. MySQL> select current_time();
  16. +----------------+
  17. | current_time() |
  18. +----------------+
  19. | 21:24:46 |
  20. +----------------+
  21. 1 row in set (0.00 sec)

MySQL Date函数 2、Unix时间

  1. MySQL> select unix_timestamp();
  2. +------------------+
  3. | unix_timestamp() |
  4. +------------------+
  5. | 1263821184 |
  6. +------------------+
  7. 1 row in set (0.00 sec)
  8. MySQL> select from_unixtime(1263821182);
  9. +---------------------------+
  10. | from_unixtime(1263821182) |
  11. +---------------------------+
  12. | 2010-01-18 21:26:22 |
  13. +---------------------------+
  14. 1 row in set (0.00 sec)

MySQL Date函数 3、时间前后

  1. MySQL> select date_add(current_timestamp, interval 1 day);
  2. +---------------------------------------------+
  3. | date_add(current_timestamp, interval 1 day) |
  4. +---------------------------------------------+
  5. | 2010-01-19 21:27:53 |
  6. +---------------------------------------------+
  7. 1 row in set (0.00 sec)
  8. MySQL> select date_add(current_time, interval 1 day);
  9. +----------------------------------------+
  10. | date_add(current_time, interval 1 day) |
  11. +----------------------------------------+
  12. | NULL |
  13. +----------------------------------------+
  14. 1 row in set, 1 warning (0.00 sec)
  15. MySQL> select date_add(current_date, interval 1 day);
  16. +----------------------------------------+
  17. | date_add(current_date, interval 1 day) |
  18. +----------------------------------------+
  19. | 2010-01-19 |
  20. +----------------------------------------+
  21. 1 row in set (0.00 sec)
  22. MySQL> select date_sub(current_timestamp, interval 1 day);
  23. +---------------------------------------------+
  24. | date_sub(current_timestamp, interval 1 day) |
  25. +---------------------------------------------+
  26. | 2010-01-17 21:28:41 |
  27. +---------------------------------------------+
  28. 1 row in set (0.00 sec)
  29. MySQL> select date_sub(current_date, interval 1 day);
  30. +----------------------------------------+
  31. | date_sub(current_date, interval 1 day) |
  32. +----------------------------------------+
  33. | 2010-01-17 |
  34. +----------------------------------------+
  35. 1 row in set (0.00 sec)
  36. MySQL> select date_sub(current_time, interval 1 day);
  37. +----------------------------------------+
  38. | date_sub(current_time, interval 1 day) |
  39. +----------------------------------------+
  40. | NULL |
  41. +----------------------------------------+
  42. 1 row in set, 1 warning (0.00 sec)

MySQL Date函数 4、时间间隔

  1. MySQL> select datediff('2010-01-18','2010-01-17');
  2. +-------------------------------------+
  3. | datediff('2010-01-18','2010-01-17') |
  4. +-------------------------------------+
  5. | 1 |
  6. +-------------------------------------+
  7. 1 row in set (0.00 sec)
  8. MySQL> select timediff('2010-01-18 12:00','2010-01-17 11:00');
  9. +-------------------------------------------------+
  10. | timediff('2010-01-18 12:00','2010-01-17 11:00') |
  11. +-------------------------------------------------+
  12. | 25:00:00 |
  13. +-------------------------------------------------+
  14. 1 row in set (0.00 sec)

MySQL Date函数 5、时间转换

  1. MySQL> select time_to_sec('25:00:00');
  2. +-------------------------+
  3. | time_to_sec('25:00:00') |
  4. +-------------------------+
  5. | 90000 |
  6. +-------------------------+
  7. 1 row in set (0.00 sec)
  8. MySQL> select sec_to_time(90000);
  9. +--------------------+
  10. | sec_to_time(90000) |
  11. +--------------------+
  12. | 25:00:00 |
  13. +--------------------+
  14. 1 row in set (0.00 sec)

以上的相关内容就是对MySQL Date函数的介绍,望你能有所收获。

MySQL Date函数的正确用法的更多相关文章

  1. MySQL Date 函数

    MySQL Date 函数 下面的表格列出了 MySQL 中最重要的内建日期函数: 函数 描述 NOW() 返回当前的日期和时间 CURDATE() 返回当前的日期 CURTIME() 返回当前的时间 ...

  2. Mysql coalesce()函数认识和用法

    Mysql coalesce()函数认识和用法   coalesce()解释:返回参数中的第一个非空表达式(从左向右):    鉴于在mysql中没有nvl()函数, 我们用coalesce()来代替 ...

  3. PHP学习笔记1.1——date()函数的多种用法,取出各种不同格式的时间,非常全面

    语法格式:date(string format.int timestamp); 参数一:format指定输出的日期和时间的格式,具体的参见下表; 参数二:timestamp是可选参数,是时间戳,如果不 ...

  4. PHP date()函数格式与用法汇总

    在页面的最前页加上 date_default_timezone_set("PRC");   /*把时间调到北京时间,php5默认为格林威治标准时间*/ date () a:   & ...

  5. 21. Date 函数

    SQL 日期 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要数据包含的只是日期部分,运行查询就不会出问题.但是,如果涉及时间,情况就有点复杂了. 在讨论 ...

  6. SQL-W3School-高级:SQL Date 函数

    ylbtech-SQL-W3School-高级:SQL Date 函数 1.返回顶部 1. SQL 日期 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要 ...

  7. NET MVC全局异常处理(一) 【转载】网站遭遇DDoS攻击怎么办 使用 HttpRequester 更方便的发起 HTTP 请求 C#文件流。 Url的Base64编码以及解码 C#计算字符串长度,汉字算两个字符 2019周笔记(2.18-2.23) Mysql语句中当前时间不能直接使用C#中的Date.Now传输 Mysql中Count函数的正确使用

    NET MVC全局异常处理(一)   目录 .NET MVC全局异常处理 IIS配置 静态错误页配置 .NET错误页配置 程序设置 全局异常配置 .NET MVC全局异常处理 一直知道有.NET有相关 ...

  8. MySQL replace函数替换字符串语句的用法(mysql字符串替换)

    MySQL replace函数我们经常用到,下面就为您详细介绍MySQL replace函数的用法,希望对您学习MySQL replace函数方面能有所启迪. 最近在研究CMS,在数据转换的时候需要用 ...

  9. MySql 学习之路-Date函数

    MySQL中重要的内建函数 函数 描述 NOW() 返回当前的日期和时间 NOW() 返回当前的日期和时间. 语法 NOW() -- 实例 -- 下面是 SELECT 语句: SELECT NOW() ...

随机推荐

  1. Java:HttpClient篇,Cookie概述,及其在HttpClient4.2中的应用

    1. Cookie 概述 Cookie是什么? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递.Cookie 包含每次用户访问站点时 Web 应用程序都可以读取 ...

  2. 在linq to entities中无法使用自定义方法

    来源: http://support.microsoft.com/kb/2588635/zh-tw (繁体)

  3. 【Android】17.3 Activity与StartedService的绑定

    分类:C#.Android.VS2015: 创建日期:2016-03-03 一.简介 除了上一节介绍的基本绑定以外,你还可以创建一个同时支持started和bound的服务.也就是说,服务可以通过调用 ...

  4. receiver type *** for instance message is a forward declaration

    转自:http://stackoverflow.com/questions/8815200/receiver-type-for-instance-message-is-a-forward-declar ...

  5. Linux下查看Raid磁盘阵列信息的方法

    Linux下查看软.硬raid信息的方法. 软件raid:只能通过Linux系统本身来查看 cat /proc/mdstat 可以看到raid级别,状态等信息. 硬件raid: 最佳的办法是通过已安装 ...

  6. rabbitmq 基本信息

    两个或多个系统间需要通过定时任务来同步数据,异构系弘的不同进程间想互调用 通讯的问题,可以用rabbitmq解决.rabbitmq擅长解决多系统 异构系统音的数据交换,也可以用于系统间服务的相互调用R ...

  7. python(25):Unicode 转成中文

    代码转换如下: if __name__ == "__main__": data = "\u5c71\u5cb3\u548c\u4e00\u5207\u4e18\u9675 ...

  8. spring boot设定mysql

    mysql创建表,制定自增,utf-8编码 create table person(id int auto_increment primary key,  name varchar(100), age ...

  9. mysql出现The total number of locks exceeds the lock table size解决办法

    mysql命令行下查看show variables like 'innodb_buffer_pool_size'; 修改innodb_buffer_pool_size值: windows下面 my.i ...

  10. js实现新闻条目滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...