美文网首页数据库-mysql
12. mysql中常用的字符与时间函数

12. mysql中常用的字符与时间函数

作者: 光小月 | 来源:发表于2018-04-20 14:31 被阅读8次

函数

  1. 日期转字符
    select date_format(now(), '%Y%m%d-%H%i%s');
    select date_format(now(), '%Y%m%d-%H%i%s') from student;
    select date_format(now(), '%Y%m%d') from student;
  2. 获取毫秒需要在应用层想办法, 数据库存储的字段类型为char
  3. 字符转日期
    select str_to_date('2018-04-17', '%y-%m-%d %H');
  4. 时间转时间戳
    select unix_timestamp(now());
  5. 字符串转时间戳
    select unix_timestamp('2018-04-17');
  6. 时间戳转字符串
    select from_unixtime(1523894400);
  7. 时间戳转字符串
    select from_unixtime(1523894400, '%Y-%m');

设置分隔符为 '$$' , mysql默认的语句分隔符为 ';'

欢迎关注,以后会不定时更新!

相关文章

网友评论

    本文标题:12. mysql中常用的字符与时间函数

    本文链接:https://www.haomeiwen.com/subject/fkoakftx.html