mysql 时间 >=_MySQL 日期与时间的处理

1.查询当前日期时间:函数有now(),localtime(),current_timestamp(),sysdate()。

48304ba5e6f9fe08f3fa1abda7d326ab.png

mysql> select now(),localtime(),current_timestamp(),sysdate();

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

| now() | localtime() | current_timestamp() | sysdate() |

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

| 2015-04-16 09:29:18 | 2015-04-16 09:29:18 | 2015-04-16 09:29:18 | 2015-04-16 09:29:18 |

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

1 row in set (0.00 sec)

48304ba5e6f9fe08f3fa1abda7d326ab.png

但是now()与sysdate()有点差异的,一个语句中now()的值是不变的,而sysdate()是动态获取的,例如

48304ba5e6f9fe08f3fa1abda7d326ab.png

mysql> select now(),sleep(2),now();

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

| now() | sleep(2) | now() |

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

| 2015-04-16 09:34:30 | 0 | 2015-04-16 09:34:30 |

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

1 row in set (2.00sec)

mysql> select sysdate(),sleep(2),sysdate();

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

| sysdate() | sleep(2) | sysdate() |

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

| 2015-04-16 09:35:15 | 0 | 2015-04-16 09:35:17 |

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

1 row in set (2.00sec)

-----有此结果可以看出,一般在生成环境中最好使用now(),当然也可以使用sysdate-is-now参数改变sysdate()的行为和now()一样------

48304ba5e6f9fe08f3fa1abda7d326ab.png

2.获取当前日期,curdate()=current_date()=current_date

48304ba5e6f9fe08f3fa1abda7d326ab.png

mysql> select curdate(),current_date(),current_date;

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

| curdate() | current_date() | current_date |

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

| 2015-04-16 | 2015-04-16 | 2015-04-16 |

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

1 row in set (0.00 sec)

48304ba5e6f9fe08f3fa1abda7d326ab.png

3.获取当前时间,curtime()=current_time()=current_time

48304ba5e6f9fe08f3fa1abda7d326ab.png

mysql> select curtime(),current_time(),current_time;

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

| curtime() | current_time() | current_time |

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

| 09:42:17 | 09:42:17 | 09:42:17 |

+--------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值