在 Oracle 9i 中获取两个日期之间的时间跨度的方法是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1845727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:35:30  来源:igfitidea点击:

What is the way to get the timespan between two dates in Oracle 9i

oracletimespan

提问by Chakra

Which is the best way in Oracle 9i to get the difference between two dates including the times ? Something like the Timespan function in C#.

在 Oracle 9i 中获取包括时间在内的两个日期之间的差异的最佳方法是什么?类似于 C# 中的 Timespan 函数。

Thanks, Chak

谢谢,查克

回答by Klaus Byskov Pedersen

When you subtract two dates you get the difference in days. If you multiply that number by 24 you have the difference in hours. Multiply that number by 60 you have the difference in minutes, etc.

当您减去两个日期时,您会得到以天为单位的差异。如果您将该数字乘以 24,您就会得到小时数的差异。将该数字乘以 60,您就会得到以分钟为单位的差异,等等。

回答by David Aldridge

You can express the difference as a numeric number of days, or as an interval data type: http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/expressions9a.htm#1033525

您可以将差异表示为天数或间隔数据类型:http: //download.oracle.com/docs/cd/B10501_01/server.920/a96540/expressions9a.htm#1033525

回答by RoadVampire

When you do subtraction between dates (type DATE), you get a number that represents the number of days (note this is of a NUMBER(p,s) type, not an INTEGER, as many T-SQL folks get confused in Oracle). Then you can convert that number into seconds by multiplying it by 24*60*60.

当您在日期之间进行减法(DATE 类型)时,您会得到一个表示天数的数字(请注意,这是 NUMBER(p,s) 类型,而不是 INTEGER,因为许多 T-SQL 人员在 Oracle 中感到困惑) . 然后,您可以将该数字乘以 24*60*60 将其转换为秒。

n_diff := ABS(date1 - date2) * 24*60*60;