简体   繁体   English

如何在netsuite中区分两个日期?

[英]How to get difference between two dates in netsuite?

I m new to netsuite ,i have to find difference between two dates in netsuite. 我是netsuite的新手,我必须找到netsuite中两个日期之间的区别。 How can i get the difference of two dates in netsuite through scripts.help me,Thanks. 如何通过脚本获取netsuite中两个日期的区别。帮助我,谢谢。

(I) Get the Difference of Two Date Fields Using an SQL Expression (I)使用SQL表达式获取两个日期字段的差异

  1. Navigate to Customization > Lists, Records, & Fields > Entity Fields > New 导航到自定义>列表,记录和字段>实体字段>新建
  2. Create the Custom Fields 创建自定义字段

Custom Field 1. 自定义字段1。

Label = Date Created 标签=创建日期
ID: datecreated ID:datecreated
Type: Date 类型:日期
Store Value: True 商店价值:真实
Applies To: Customer 适用于:客户
Display > Subtab: Main 显示>子选项卡:主要

Custom Field 2. 自定义字段2。

Label: Date Closed 标签:关闭日期
ID: dateclosed ID:dateclosed
Type: Date 类型:日期
Store Value: True 商店价值:真实
Applies To: Customer 适用于:客户
Display > Subtab: Main 显示>子选项卡:主要

Custom Field 3. 自定义字段3。

Label: Days Open 标签:天开放
Type: Date 类型:日期
Store Value: False 商店价值:错误
Applies To: Customer 适用于:客户
Display > Subtab: Main 显示>子选项卡:主要
Validation and Defaulting > Formula: T 验证和默认>公式:T
Formula field: {dateclosed}-{datecreated} 公式字段: {dateclosed}-{datecreated}

  1. Pull up any Customer record > Fill out the custom fields. 拉起任何客户记录>填写自定义字段。

For example: 例如:

Date Created = 9/1/2014 创建日期= 9/1/2014
Date Closed = 9/3/2014 截止日期= 2014年9月3日

  1. Click Save. 单击保存。
  2. Days Open field should show the value of 2. Days Open字段应显示值2。

(II) Calculate the Difference between a Date/Time field and a Date field Using Formula (II)使用公式计算日期/时间字段和日期字段之间的差异

The following formula will give you the difference in days. 以下公式将为您提供天数差异。 You can add this to the results tab of your saved search. 您可以将其添加到已保存搜索的结果标签中。

Formula(Numeric): ROUND({ID of date field}-{ID of other date field})

Note: Either field can be used for the date/time field value. 注意:任一字段都可用于日期/时间字段值。

(III) Using SuiteScript Code (III)使用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;
}

You can convert a Text date ('01/01/2014') to a Date object with nlapiStringtoDate. 您可以使用nlapiStringtoDate将文本日期('01 / 01/2014')转换为Date对象。

So basically you go 所以基本上你去吧

timeDiff = Math.abs(nlapiStringtoDate(myDate).getTime() - (new Date).getTime()) diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

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

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