简体   繁体   English

如何在Oracle中以毫秒为单位获取日期时差

[英]How to take date time difference by milliseconds in Oracle

In my requirement, I need to take the difference between date time by milliseconds.在我的要求中,我需要以毫秒为单位计算日期时间之间的差异。 its most of the time receiving correctly, but in sometimes, it shows minus value.它大部分时间都能正确接收,但有时会显示负值。

in my table I'm storing EXPIREDDATE as follows, to update EXPIREDDATE time by 2 hours在我的表中,我按如下方式存储EXPIREDDATE ,以将 EXPIREDDATE 时间更新 2 小时

UPDATE nd_user_encode_keys
SET EXPIREDDATE = SYSDATE + ( 1 / 1440 * 120)  -- here 120 means 2 hours

and according to my SP, above query running before the below query.根据我的 SP,上面的查询在下面的查询之前运行。

SELECT (EXPIRYDATETIME - SYSDATE) * 24 * 60 * 60 * 1000 as EXPIRYDATETIMEINMILISECONDS

My problem is most of the time result is 7200000 , but somtimes it shows minus value like this -34932000 .我的问题是大多数时候结果是7200000 ,但有时它会显示负值,就像这样-34932000 what could be the reason for this issue.这个问题的原因可能是什么。 can someone please explain.有人可以解释一下吗?

When you have A - B , then the result can be:当你有A - B时,结果可以是:

  • 0, if A = B 0,如果A = B
  • a positive number, if A > B一个正数,如果A > B
  • a negative number, if A < B --> that is your case一个负数,如果A < B --> 那是你的情况

Why is expirydatetime less than sysdate and is that a valid value, I wouldn't know, but you should as it is your database, you're storing values into that table.为什么expirydatetime小于sysdate并且它是一个有效值,我不知道,但你应该因为它是你的数据库,你将值存储到该表中。

According to update statement you posted, and regarding the fact that sysdate won't return the same value "right now" as it did "a few moments ago", then it depends on when you ran that update .根据您发布的update声明,以及关于sysdate不会“立即”返回与“几分钟前”相同的值这一事实,这取决于您何时运行该update

Therefore, I presume it is about time difference between update and select .因此,我认为这是关于updateselect之间的时间差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM