我是 netsuite 的新手,我必须在 netsuite 中找出两个日期之间的差异。 我如何通过脚本获取netsuite中两个日期的差异。帮助我,谢谢。
最佳答案
(I) 使用 SQL 表达式获取两个日期字段的差异
- 导航到自定义 > 列表、记录和字段 > 实体字段 > 新建
- 创建自定义字段
自定义字段 1.
Label = Date Created
ID: datecreated
Type: Date
Store Value: True
Applies To: Customer
Display > Subtab: Main
自定义字段 2.
Label: Date Closed
ID: dateclosed
Type: Date
Store Value: True
Applies To: Customer
Display > Subtab: Main
自定义字段 3.
Label: Days Open
Type: Date
Store Value: False
Applies To: Customer
Display > Subtab: Main
Validation and Defaulting > Formula: T
Formula field:{dateclosed}-{datecreated}
- 调出任何客户记录 > 填写自定义字段。
例如:
创建日期 = 9/1/2014
关闭日期 = 2014 年 9 月 3 日
- 点击保存。
- 开放天数字段应显示值 2。
(二)使用公式计算日期/时间字段与日期字段的差值
以下公式将为您提供天数差异。您可以将其添加到已保存搜索的结果选项卡中。
Formula(Numeric): ROUND({ID of date field}-{ID of other date field})
注意:任一字段均可用作日期/时间字段值。
(三)使用SuiteScript代码
function date_difference(date1, date2) {
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // Get 1 day in milliseconds
return diffDays;
}
关于javascript - 如何在 netsuite 中获取两个日期之间的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26334088/