oracle日期字段添加数字字段
add number filed to date filed in oracle
我正在尝试向现有日期添加秒数以查找结束时间。我在一个字段中有开始时间,在一个字段中有总持续时间,我在互联网上发现我们可以添加日期但我们应该 dived on 86400
(chargestarttime + (NVL (callduration, 0) / 86400))
// where chargestarttime is date , callduration is number
// sample (chargestarttime is 2020-05-30 02:21:58 and callduration is 65 the output is 2020-05-30 02:23:03)
我的问题是为什么我们需要在 86400 上 div?如果我将日期转换为 UNIX_TIMESTAMP 然后只添加 65,它将在 86400(24 小时)没有 div 的情况下给出相同的结果,或者我们有理由在 86400( 24 小时)
why we need to div on 86400?
在日期运算中,Oracle 使用1
来表示 1 天。如果您从秒数开始,则需要将其转换为天数,因此
chargestarttime + NVL(callduration, 0) / 60 / 60 / 24
-- seconds per minutes-----^
-- minutes per hour -----^
-- hours per day -----^
86400
就是一天有多少秒。
您的查询将秒数添加为一整天的一小部分(即 1 天 = 24 小时 = 1440 分钟 = 86400 秒)。
或者,您可以使用 INTERVAL
数据类型直接向日期添加秒数:
chargestarttime + NVL(callduration, 0) * INTERVAL '1' SECOND
或
chargestarttime + NUMTODSINTERVAL( NVL(callduration, 0), 'SECOND' )
我正在尝试向现有日期添加秒数以查找结束时间。我在一个字段中有开始时间,在一个字段中有总持续时间,我在互联网上发现我们可以添加日期但我们应该 dived on 86400
(chargestarttime + (NVL (callduration, 0) / 86400))
// where chargestarttime is date , callduration is number
// sample (chargestarttime is 2020-05-30 02:21:58 and callduration is 65 the output is 2020-05-30 02:23:03)
我的问题是为什么我们需要在 86400 上 div?如果我将日期转换为 UNIX_TIMESTAMP 然后只添加 65,它将在 86400(24 小时)没有 div 的情况下给出相同的结果,或者我们有理由在 86400( 24 小时)
why we need to div on 86400?
在日期运算中,Oracle 使用1
来表示 1 天。如果您从秒数开始,则需要将其转换为天数,因此
chargestarttime + NVL(callduration, 0) / 60 / 60 / 24
-- seconds per minutes-----^
-- minutes per hour -----^
-- hours per day -----^
86400
就是一天有多少秒。
您的查询将秒数添加为一整天的一小部分(即 1 天 = 24 小时 = 1440 分钟 = 86400 秒)。
或者,您可以使用 INTERVAL
数据类型直接向日期添加秒数:
chargestarttime + NVL(callduration, 0) * INTERVAL '1' SECOND
或
chargestarttime + NUMTODSINTERVAL( NVL(callduration, 0), 'SECOND' )