zoukankan      html  css  js  c++  java
  • MySQL 时间戳(Timestamp)函数 Leone

    1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp() mysql> select current_timestamp, current_timestamp(); +---------------------+---------------------+ | current_timestamp | current_timestamp() | +---------------------+---------------------+ | 2008-08-09 23:22:24 | 2008-08-09 23:22:24 | +---------------------+---------------------+ 2. MySQL (Unix 时间戳、日期)转换函数: unix_timestamp(), unix_timestamp(date), from_unixtime(unix_timestamp), from_unixtime(unix_timestamp,format) 下面是示例: select unix_timestamp(); -- 1218290027 select unix_timestamp('2008-08-08'); -- 1218124800 select unix_timestamp('2008-08-08 12:30:00'); -- 1218169800 select from_unixtime(1218290027); -- '2008-08-09 21:53:47' select from_unixtime(1218124800); -- '2008-08-08 00:00:00' select from_unixtime(1218169800); -- '2008-08-08 12:30:00' select from_unixtime(1218169800, '%Y %D %M %h:%i:%s %x'); -- '2008 8th August 12:30:00 2008' 3. MySQL 时间戳(timestamp)转换、增、减函数: timestamp(date) -- date to timestamp timestamp(dt,time) -- dt + time timestampadd(unit,interval,datetime_expr) -- timestampdiff(unit,datetime_expr1,datetime_expr2) -- 请看示例部分: select timestamp('2008-08-08'); -- 2008-08-08 00:00:00 select timestamp('2008-08-08 08:00:00', '01:01:01'); -- 2008-08-08 09:01:01 select timestamp('2008-08-08 08:00:00', '10 01:01:01'); -- 2008-08-18 09:01:01 select timestampadd(day, 1, '2008-08-08 08:00:00'); -- 2008-08-09 08:00:00 select date_add('2008-08-08 08:00:00', interval 1 day); -- 2008-08-09 08:00:00 MySQL timestampadd() 函数类似于 date_add()。 select timestampdiff(year,'2002-05-01','2001-01-01'); -- -1 select timestampdiff(day ,'2002-05-01','2001-01-01'); -- -485 select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00'); -- -12 select datediff('2008-08-08 12:00:00', '2008-08-01 00:00:00'); -- 7 MySQL timestampdiff() 函数就比 datediff() 功能强多了,datediff() 只能计算两个日期(date)之间相差的天数
  • 相关阅读:
    nodejs与bat结合的定时查询功能-代码中逻辑定时去查询仪器列表是否需要送去校验
    php中数组方法-array_map的作用域问题
    内网穿透-让本地项目可以被外部访问到
    Registry key 'SoftwareJavaSoftJava Runtime EnvironmentCurrentVersion' has value '1.8', but '1.7'
    (转) IntelliJ IDEA2018激活
    (转) weblogic 12c忘记密码
    (转) Linux权限管理(基本权限、默认权限)
    (转) 报文格式【定长报文】
    (转) ESB 企业服务总线基本内容概述
    java基础知识思维导图
  • 原文地址:https://www.cnblogs.com/doseoer/p/4007637.html
Copyright © 2011-2022 走看看