1、MySQL 获得当前日期时间函数
获得当前日期+时间(date + time)函数:now()
mysql>selectnow();
+---------------------+
|now()|
+---------------------+
|-08-0822:20:46|
+---------------------+
获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。看下面的例子就明白了:
mysql>selectnow(),sleep(3),now();
+---------------------+----------+---------------------+
|now()|sleep(3)|now()|
+---------------------+----------+---------------------+
|-08-0822:28:21|0|-08-0822:28:21|
+---------------------+----------+---------------------+
sysdate() 日期时间函数,一般情况下很少用到。
MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
mysql>selectcurrent_timestamp,current_timestamp();
+---------------------+---------------------+
|current_timestamp|current_timestamp()|
+---------------------+---------------------+
|-08-0923:22:24|-08-0923:22:24|
+---------------------+---------------------+
2、MySQL 日期转换函数、时间转换函数
MySQL Date/Time to Str(日期/时间转换为字符串)函数:date_format(date,format), time_format(time,format)
mysql>selectdate_format(-08-0822:23:01,\%Y%m%d%H%i%s);
+----------------------------------------------------+
|date_format(-08-0822:23:01,\%Y%m%d%H%i%s)|
+----------------------------------------------------+
|0808222301|
+--------------------------------------------------