oracle TIMESTAMP时间差(分钟)

方式一、EXTRACT 方式计算

·原文连接 : https://www.cnblogs.com/xqzt/p/4477239.html
SELECT
	EXTRACT (DAY FROM dt2 - dt1) DAY,
	EXTRACT (HOUR FROM dt2 - dt1) HOUR,
	EXTRACT (MINUTE FROM dt2 - dt1) MINUTE,
	EXTRACT (SECOND FROM dt2 - dt1) SECOND
FROM
	(
		SELECT
			TO_TIMESTAMP ('2020-02-04 15:07:00','yyyy-mm-dd hh24:mi:ss') dt1,
			TO_TIMESTAMP ('2020-09-23 16:50:46','yyyy-mm-dd hh24:mi:ss') dt2
		FROM
			dual
	)

 方式二、TO_DATE 方式计算

·原文连接 :https://blog.csdn.net/jsut_rick/article/details/100730000
SELECT
	CEIL ( (
			TO_DATE (
				TO_CHAR ( dt2, 'yyyy-mm-dd hh24:mi:ss' ), 'yyyy-mm-dd hh24:mi:ss') 
			- TO_DATE (
				TO_CHAR (dt1, 'yyyy-mm-dd hh24:mi:ss' ), 'yyyy-mm-dd hh24:mi:ss')
		) * 24 * 60 )  m
FROM
	(
		SELECT
			TO_TIMESTAMP ('2020-02-04 15:07:00','yyyy-mm-dd hh24:mi:ss') dt1,
			TO_TIMESTAMP ('2020-09-23 16:50:46','yyyy-mm-dd hh24:mi:ss') dt2
		FROM
			dual
	)

  

上一篇:hdu6888(区间取max,维护连续最小值段数)


下一篇:8月6 day3