Oracle:如何减去两个日期并获得结果的分钟数

Oracle : how to subtract two dates and get minutes of the result(Oracle:如何减去两个日期并获得结果的分钟数)

本文介绍了Oracle:如何减去两个日期并获得结果的分钟数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这个函数来获取某个日期的分钟数,但我无法获取两个日期之间的分钟数,如何获取?

I wrote this function to get minutes from a date, but I cannot get minutes between two dates, How to get that ?

FUNCTION get_minute(p_date DATE)
RETURN NUMBER
IS
BEGIN
    IF p_date IS NOT NULL THEN
        return  EXTRACT(MINUTE FROM TO_TIMESTAMP(to_char(p_date,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH24:MI:SS'));
    ELSE
        RETURN 0;
    END IF;
END get_minute;

推荐答案

当你在 Oracle 中减去两个日期时,你会得到两个值之间的天数.所以你只需要在几分钟内乘以得到结果:

When you subtract two dates in Oracle, you get the number of days between the two values. So you just have to multiply to get the result in minutes instead:

SELECT (date2 - date1) * 24 * 60 AS minutesBetween
FROM ...

这篇关于Oracle:如何减去两个日期并获得结果的分钟数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Oracle:如何减去两个日期并获得结果的分钟数

基础教程推荐