MySQL日期的相关函数介绍


  本文标签:MySQL日期

  数据库中日期和时间都是很重要的,下面就为您介绍几个和MySQL日期时间相关的函数,供您参考,希望对您学习MySQL日期时间方面有所帮助  。

  获得当前日期(date)函数:curdate()

  mysql> select curdate();

  +------------+
| curdate() |
+------------+
| 2008-08-08 |
+------------+
其中,下面的两个日期函数等同于 curdate():

  current_date()
,current_date

  获得当前时间(time)函数:curtime()

  mysql> select curtime();

  +-----------+
| curtime() |
+-----------+
| 22:41:30 |
+-----------+
其中,下面的两个时间函数等同于 curtime():

  current_time()
,current_time

  获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()

  mysql> select utc_timestamp(), utc_date(), utc_time(), now()

  +---------------------+------------+------------+---------------------+
| utc_timestamp() | utc_date() | utc_time() | now() |
+---------------------+------------+------------+---------------------+
| 2008-08-08 14:47:11 | 2008-08-08 | 14:47:11 | 2008-08-08 22:47:11 |
+---------------------+------------+------------+---------------------+
因为我国位于东八时区,所以本地时间 = UTC 时间 + 8 小时  。UTC 时间在业务涉及多个国家和地区的时候,非常有用  。

  以上就是MySQL日期的相关函数介绍  。