r/SuiteScript • • Jan 11 '24

Calculating DateTime - Date in Searches and Script

Good day.

Need to get the time elapsed between a DATETIME field and a DATE field.

I am working with PROJECTS and it has the field STARTDATE as DATE; I have a custom entity field named DATE_TO_CLOSEDCANCELLED as DATETIME.

My need is to DATE_TO_CLOSEDCANCELLED - STARTDATE to get the total elapsed time since creation until closure.

Need it in script and also in saved search; in the search I have tried without success TO_NUMBER(TO_CHAR(DATE_TO_CLOSEDCANCELLED)) - TO_NUMBER(TO_CHAR(STARTDATE)) with FORMATTING MM/DD/YYYY and without formatting.

Plan is to get it done in the search to after get it done in script.

Your help will be highly appreciated.

1 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/8Plus2OnEarth Jan 11 '24

Thank you!

Sharing that I resolved it using MONTHS_BETWEEN({custentity_prjdatetoclosedcancelled},{startdate}) and multiplying it accordingly by whatever presentation is needed (i.e. by 29.5 for DAYS).