如何在NRQL中找到不同格式的2个日期之间的天数?
我必须使用NRQL找到新遗物中的2种不同日期格式之间的差异。
以下查询返回 从ABC
2023-01-27,2022年4月13日, 选择最新(Expiresat),最新(dateof(Timestamp)) 作为输出。 现在,我必须找到这两个不同格式的日期之间的天数。我该怎么做?
I have to find difference between 2 different date formats in new relic using NRQL.
The below query returnsSELECT latest(expiresAt),latest(dateOf(timestamp)) FROM abc
2023-01-27,April 13, 2022
as output.
Now i have to find number of days between these two dates of different format. How can i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NR 中的本机
timestamp
字段是以毫秒为单位的 unix 纪元时间戳。假设expiresAt
是您要发送的自定义字段,您应该将其格式化为与timestamp
相同的 unix 毫秒格式,这样您就可以计算天数,如下所示:SELECT (latest(expiresAt) -latest(timestamp))/(1000*60*60*24) FROM abc
如果不可能,您可以使用 Synthetics 来创建一个脚本化监视器,该监视器将通过 API 运行该查询,返回时间戳/expiresAt 值,然后使用本机 JS
Date
对象转换两个结果以减去并获取天数。The native
timestamp
field in NR is a unix epoch timestamp in milliseconds. AssumingexpiresAt
is a custom field that you are sending, you should format it in the same unix milliseconds format astimestamp
, that way you could calculate the # of days like this:SELECT (latest(expiresAt) - latest(timestamp))/(1000*60*60*24) FROM abc
If that isn't possible, you could use Synthetics to create a scripted monitor that will run that query via API, return the timestamp/expiresAt values, and then convert both results using the native JS
Date
object to subtract and get the # of days.