mysql 中,计算2个datetime类型的字段,相减得到的分钟数

计算id=1与id=2的时间差(分钟)mysql> select (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 from (select from timeminus where id=2) a inner join (select * from timeminus where id=1) b ;+---+ | (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 | +---...
mysql 中,计算2个datetime类型的字段,相减得到的分钟数
下载好后,双击安装就可以。
可以升级任意 SQL Server 2008 版本。Service Pack 2 包含 SQL Server 实用工具和数据层应用程序 (DAC) 的更新,还包含关于 Microsoft Reporting Services 与 Microsoft SharePoint 2010 Technologies 的集成功能的更新。Service Pack 2 引入了对数据库中最多 15,000 个分区的支持,并且包括 SQL Server 2008 SP1 累积更新 1 到 8。
Microsoft SQL Server 2008 Service Pack 1 不是安装 SQL Server 2008 Service Pack 2 的先决条件。(就是说,没有安装过Service Pack 1,也可以直接安装Service Pack 2)2011-10-03
sql server : datediff(“mi”,stime,getdate())
mysql: datediff(stime,now()) 得到的是“天数”的差值;
unix_timestamp(stime),就能得到秒数的差值了, (返回值:自'1970-01-01 00:00:00'的到stime的秒数差)2013-05-24
阿斯2011-09-20
now()-stime 得到的是minute * 100,这个数值的与分钟的单位换算是100=1分钟,超过60分钟这个数值无效。

得到时间差:
select (unix_timestamp(now())-unix_timestamp(stime))/60 from table_name where whew_condition;

mysql> select * from timeminus;
+----+---------------------+
| id | stime |
+----+---------------------+
| 1 | 2011-09-21 09:30:00 |
| 2 | 2011-09-21 11:30:00 |
| 3 | 2011-09-20 00:00:00 |
+----+---------------------+
3 rows in set (0.02 sec)

# 计算id=1与id=2的时间差(分钟)
mysql> select (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 from (select
* from timeminus where id=2) a inner join (select * from timeminus where id=1) b
;
+------------------------------------------------------+
| (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 |
+------------------------------------------------------+
| 120.0000 |
+------------------------------------------------------+
1 row in set (0.00 sec)2011-09-21
mengvlog 阅读 8 次 更新于 2025-07-19 23:53:48 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部