Calculation Fields - Difference between two date fields

Hi,

Have two date fields for which I need to calculate the difference in days, i.e. UsrEndDate- UsrStartDate = UsrDayDifference

I have implemented the following code so far:

 

define("AccountPageV2", [], function() {

return {

entitySchemaName: "Account",

details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,

attributes: {

        "UsrDayDifference": {

               dataValueType: Terrasoft.DataValueType.FLOAT,

               dependencies: [

                   {

                       columns: ["UsrStartDate", "UsrEndDate"],

                       methodName: "calculateDays"

                   }

               ]

           }

},

 

 methods: {

            onEntityInitialized: function() {

                this.callParent(arguments);

                this.calculateDays();

            },

            calculateDays: function() {

                var result = (this.get("UsrEndDate") - this.get("UsrStartDate")).TotalDays;

                this.set("UsrDayDifference", result);

            }

        },

diff: /**SCHEMA_DIFF*/[

{

............

 

 

Can someone please explain what I'm doing wrong here?

 

 

Thank you,

 

Eduan

Like 0

Like

1 comments

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}
span.Apple-tab-span {white-space:pre}

You can use this function: 

 

        numberOfDays: function(date1, date2) {

                if (date1 instanceof Date && date2 instanceof Date) {

                    var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds

                    var diffDays = Math.round(Math.abs((date1.getTime() - date2.getTime()) / oneDay));

                    return diffDays;

                }

                else {

                    return 0;

                }

            },

 

 

I hope it works for you.

Show all comments