MySQL获取时间函数
来源:互联网 发布:魔兽世界单机版数据库 编辑:程序博客网 时间:2024/05/24 01:46
1、 获得当前日期+时间(date + time)函数:now()
3 、获得当前日期(date)函数:curdate() 等同于:current_date(),current_date
5 、获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()
mysql> SELECT now();+---------------------+| now() |+---------------------+| 2017-06-15 09:16:56 |+---------------------+1 row in set (0.00 sec)
2、 获得当前日期+时间(date + time)函数:sysdate()
mysql> SELECT sysdate();+---------------------+| sysdate() |+---------------------+| 2017-06-15 09:17:17 |+---------------------+1 row in set (0.00 sec)sysdate() 日期时间函数跟和now() 返回的数据格式一样,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。
测试:
mysql> SELECT now(), sleep(5), now();+---------------------+----------+---------------------+| now() | sleep(5) | now() |+---------------------+----------+---------------------+| 2017-06-15 09:20:59 | 0 | 2017-06-15 09:20:59 |+---------------------+----------+---------------------+1 row in set (5.11 sec)其返回的两个值是一样的,因为都是表示语句开始执行的时间。
mysql> SELECT sysdate(), sleep(5), sysdate();+---------------------+----------+---------------------+| sysdate() | sleep(5) | sysdate() |+---------------------+----------+---------------------+| 2017-06-15 09:21:43 | 0 | 2017-06-15 09:21:48 |+---------------------+----------+---------------------+1 row in set (5.00 sec)
3 、获得当前日期(date)函数:curdate() 等同于:current_date(),current_date
mysql> SELECT curdate(), current_date(), current_date;+------------+----------------+--------------+| curdate() | current_date() | current_date |+------------+----------------+--------------+| 2017-06-15 | 2017-06-15 | 2017-06-15 |+------------+----------------+--------------+1 row in set (0.00 sec)4、获得当前时间(time)函数:curtime()等同于:current_time(),current_time
mysql> SELECT curtime(), current_time(), current_time;+-----------+----------------+--------------+| curtime() | current_time() | current_time |+-----------+----------------+--------------+| 09:28:11 | 09:28:11 | 09:28:11 |+-----------+----------------+--------------+1 row in set (0.00 sec)
5 、获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()
因为我国位于东八时区,所以本地时间 = UTC 时间 + 8 小时。
mysql> SELECT utc_date(), utc_time(), utc_timestamp();+------------+------------+---------------------+| utc_date() | utc_time() | utc_timestamp() |+------------+------------+---------------------+| 2017-06-15 | 01:28:52 | 2017-06-15 01:28:52 |+------------+------------+---------------------+1 row in set (0.00 sec)6、获得Unix系统中的时间戳
mysql> SELECT unix_timestamp();+------------------+| unix_timestamp() |+------------------+| 1497490186 |+------------------+1 row in set (0.00 sec)
阅读全文
0 0
- MySQL获取时间函数
- 获取当前时间的MySql时间函数
- MySQL-获取当天时间、前几天时间函数
- MySQL时间函数-获取当前时间-时间差
- MySQL获取系统当前时间的函数
- mysql获取当前时间的几个函数
- MySQL获取系统当前时间的函数
- MySQL获取时间及日期的函数--sysdate()
- mysql数据库函数获取时间中的年月日时分秒
- mysql 获取系统时间
- mysql获取系统时间
- Mysql获取时间
- Mysql获取时间
- MySql获取系统时间
- mysql 获取系统时间
- MySql获取系统时间
- Mysql时间获取
- Mysql获取特定时间
- pv vg lv fs 概念区别
- 深入理解STL源码--空间配置器(allocator)
- mysql——explain分析
- Coderforces Queue at the School
- Http-Get/Post获取数据设置
- MySQL获取时间函数
- TensorFlow之深入理解VGG\Residual Network
- SylixOS注册USB驱动模块
- MYSql 启动MySql ,连接,创建数据库,选择数据库,删除数据库
- HDU 2064 汉诺塔III
- oracle 中d.biz_id =e.case_id(+)是什么意思?
- 一行神奇python
- 创建和检索索引
- java中Map集合的取出方式