Mysql时间操作

一、MySql时间戳转换

sql 复制代码
select unix_timestamp();  #获取时间戳格式时间
select FROM_UNIXTIME(1717399499); #将时间戳转换为普通格式时间

二、Mysql时间相加减结果转换为秒

方法1:time_to_sec(timediff(endTime, startTime))

sql 复制代码
SELECT
  DISTINCT(column1),
  min(last_modified_time),
  max(last_modified_time),
  time_to_sec(
    timediff(max(last_modified_time), min(last_modified_time))
  ) as time1
FROM
  table1
where
  column1 = 'aaa';

方法2:timestampdiff(second, startTime, endTime)

sql 复制代码
SELECT
  DISTINCT(column1),
  min(last_modified_time),
  max(last_modified_time),
  timestampdiff(
    second,
    min(last_modified_time),
    max(last_modified_time)
  ) as time2
FROM
  table1
where
  column1 = 'aaa';

方法3:unix_timestamp(endTime) -unix_timestamp(startTime)

sql 复制代码
SELECT
  DISTINCT(column1),
  min(last_modified_time),
  max(last_modified_time),
  unix_timestamp(max(last_modified_time)) - unix_timestamp(min(last_modified_time)) as time3
FROM
  table1
where
  column1 = 'aaa';

三、Mysql时间相加减结果为时分秒

方法:timediff(time1,time2)

sql 复制代码
SELECT
  column1,
  max(last_modified_time),
  min(last_modified_time),
    timediff(
      max(last_modified_time),
      min(last_modified_time)
  )
FROM
  table1
where
  column1 = 'aaa';
相关推荐
nongcunqq2 小时前
abap 操作 excel
java·数据库·excel
rain bye bye3 小时前
calibre LVS 跑不起来 就将setup 的LVS Option connect下的 connect all nets by name 打开。
服务器·数据库·lvs
冻咸鱼3 小时前
MySQL的配置
mysql·配置
阿里云大数据AI技术4 小时前
云栖实录|MaxCompute全新升级:AI时代的原生数据仓库
大数据·数据库·云原生
不剪发的Tony老师5 小时前
Valentina Studio:一款跨平台的数据库管理工具
数据库·sql
weixin_307779135 小时前
在 Microsoft Azure 上部署 ClickHouse 数据仓库:托管服务与自行部署的全面指南
开发语言·数据库·数据仓库·云计算·azure
六元七角八分5 小时前
pom.xml
xml·数据库
虚行5 小时前
Mysql 数据同步中间件 对比
数据库·mysql·中间件
奥尔特星云大使5 小时前
mysql读写分离中间件Atlas安装部署及使用
数据库·mysql·中间件·读写分离·atlas
牛马baby6 小时前
【mysql】in 用到索引了吗?
数据库·mysql·in