Creator Scripts.
Creator Scripts.
Zoho Trusted Partner in Digital Transformation

How to calculate the elapsed time between two Date-Time fields

25.07.13 03:10 PM By FMRR




I have found several functions, scripts and blogs providing different methods to calculate the elapsed time between two date-time fields. However, most of them are hard to understand or involve a higher coding of deluge scripting to obtain the desired result.

Below you will find a solution in 3 lines of code if the Dates belong to the same day

Hr=(input.End_Time.getHour() -  input.Start_Time.getHour());
Min=(input.End_Time.getMinutes()  /  60  -  input.Start_Time.getMinutes()  /  60);
Elapsed=(Hr  +  Min);

Or 7 lines of code If the Dates vary in Days ...

if(input.Start_Time.getDayOfWeek()  ==  input.End_Time.getDayOfWeek())
{
Hr=(input.End_Time.getHour()  -  input.Start_Time.getHour());
Min=(input.End_Time.getMinutes()  /  60  -  input.Start_Time.getMinutes()  /  60);
Elapsed=(Hr  +  Min);
}
else if(input.Start_Time.getDayOfWeek()  <  input.End_Time.getDayOfWeek())
{
Hr=(input.End_Time.getHour()  -  input.Start_Time.getHour());
Min=(input.End_Time.getMinutes()  /  60  -  input.Start_Time.getMinutes()  /  60);
Day=((input.End_Time.getDayOfYear()  -  input.Start_Time.getDayOfYear())  *  24);
Elapsed=(Day  +  Hr  +  Min);
}

In the following link you will be able to test the script on a live and free application. Elapsed Time

You may locate the following code in the following places: On user input, On Add On Success, or On Edit On Success

Hope it helps....enjoy.

Discover a treasure trove of valuable content related to Zoho Creator! If you found this post insightful, you'll love delving into our collection of informative articles covering various aspects of Zoho Creator. From advanced techniques to workflow optimization, our blog offers a wealth of knowledge to help you master the platform. Keep exploring and unlock the full potential of Zoho Creator for your business needs. Happy Reading!

How do I create a custom function in Zoho Creator?

To create a custom function in Zoho Creator, follow these steps:
1. Go to your Zoho Creator application and click on "Settings".
2. Under "Customization", select "Functions".
3. Click on the "Add Function" button.
4. Give your function a name and write the Deluge script for the function.
5. Click "Save" to create the custom function.

Can you customize Zoho Creator?

Yes, you can customize Zoho Creator to tailor it to your specific needs. You can create custom functions, add workflows, design personalized forms, and build unique reports to optimize your application's performance.

How do you write a function in Zoho?

To write a function in Zoho, you can use the Deluge scripting language. Deluge allows you to perform various actions, such as manipulating data, creating custom workflows, and implementing business logic, all within the Zoho platform.

How do I add a custom function in Zoho CRM?

To add a custom function in Zoho CRM, follow these steps:
1. Open your Zoho CRM account and go to "Settings".
2. Under "Customization", select "Module Customization".
3. Click on "Scripts" and then "Functions".
4. Create a new function and write the Deluge script for the function.
5. Save the function to add it to Zoho CRM.

How do I add a formula in Zoho Creator?

To add a formula in Zoho Creator, you can use the Formula field type. When creating or editing a field, select "Formula" as the field type, and then write the formula using field references and mathematical operators to calculate the desired value.

FMRR