In this blog, we will explore how to perform time calculations in Navision using the AL language.

We will look at several practical examples that will help you understand and apply these techniques in your projects. Time calculations are essential for many business applications, from schedule management to project tracking.
Learning to handle these calculations in Navision can significantly improve the efficiency of your processes.

Example 1: Subtract Two Times in Navision (Dynamics NAV) Using the AL Language
Code to Subtract Two Times in Navision (Dynamics NAV) Using the AL Language
LOCAL PROCEDURE RestarDosTiempos();
VAR
t1: Time;
t2: Time;
t3: Time;
i: Decimal;
BEGIN
t1 := 115000T;
t2 := 125100T;
i := t2 – t1;
t3 := 000000T;
// Convertir a segundos
i := i / 1000;
t3 := t3 + (i MOD 60) * 1000;
// Convertir a minutos
i := i DIV 60;
t3 := t3 + (i MOD 60) * 1000 * 60;
// Convertir a horas
i := i DIV 60;
t3 := t3 + (i MOD 60) * 1000 * 60 * 60;
MESSAGE(FORMAT(t3));
END;
Explanation of the Code for Subtracting Two Times in Navision (Dynamics NAV) Using the AL Language

This procedure subtracts two times (t1 and t2), converts the difference into seconds, minutes, and hours, and displays the result.
First, the times are converted into seconds, then into minutes, and finally into hours. This modular approach makes it easier to understand and modify the code as needed.
Example 2: Add Two Times in Navision (Dynamics NAV) Using the AL Language
Code to Add Two Times in Navision (Dynamics NAV) Using the AL Language
LOCAL PROCEDURE SumarDosTiempos();
VAR
t1: Time;
t2: Time;
t3: Time;
BEGIN
t1 := 080000T; // 08:00:00
t2 := 023000T; // 02:30:00
t3 := t1 + t2;
MESSAGE(FORMAT(t3)); // Muestra 10:30:00
END;
Explanation of the Code for Adding Two Times in Navision (Dynamics NAV) Using the AL Language
This procedure adds two times (t1 and t2) and displays the result. Adding times is useful in scenarios where you need to combine durations, such as the total time worked in a day.

Example 3: Calculate the Difference in Minutes in Navision (Dynamics NAV) Using the AL Language
Code to Calculate the Difference in Minutes in Navision (Dynamics NAV) Using the AL Language
LOCAL PROCEDURE DiferenciaEnMinutos();
VAR
t1: Time;
t2: Time;
minutos: Integer;
BEGIN
t1 := 090000T; // 09:00:00
t2 := 103000T; // 10:30:00
minutos := (t2 – t1) DIV 60000;
MESSAGE(STRSUBSTNO(‘La diferencia es %1 minutos’, minutos));
END;
Explanation of the Code for Calculating the Difference in Minutes in Navision (Dynamics NAV) Using the AL Language

This procedure calculates the difference in minutes between two times (t1 and t2) and displays the result. Calculating the difference in minutes is especially useful for time‑tracking tasks and project management.
Read also: Extract numbers from text in Business Central
Introduction to the AL Language and Tips for Developers
The AL language is the programming language used in Microsoft Dynamics 365 Business Central, formerly known as Navision.

This language is specifically designed to develop and customize applications within the Business Central environment, allowing developers to create tailored solutions that integrate seamlessly with the ERP’s standard functionality.
What is the AL Language?
AL, which stands for “Application Language”, is an event‑based programming language that allows developers to write code to customize and extend the capabilities of Business Central.
AL is used to create extensions, which are customization packages that can be deployed without modifying the system’s base code.
This makes updates and maintenance easier, as extensions can be managed independently.
Read: What do we need to develop in Dynamics 365 Business Central?
The Role of AL Developers
Developers working with AL play a crucial role in customizing and optimizing Business Central to meet the specific needs of companies.

These professionals must have a solid understanding of business logic and be able to translate customer requirements into efficient technical solutions. In addition, they should be familiar with the development environment of Visual Studio Code (VSCode), which is the main tool for writing and debugging AL code.
Tips for AL Developers

- Get Familiar with VSCode: Visual Studio Code is the recommended integrated development environment (IDE) for working with AL. Make sure to install the AL Language extension to take full advantage of all language‑specific features.
- Understand the Structure of Business Central: Before you start programming, it is important to have a solid understanding of the structure and components of Business Central. This includes tables, pages, reports, and codeunits.
- Use Sandboxes for Testing: Take advantage of sandbox environments to test your developments without affecting the production environment. Sandboxes allow you to perform testing and debugging in a safe and controlled setting.
- Follow Coding Best Practices: Keep your code clean and well documented. Use descriptive variable names and follow the coding conventions recommended by Microsoft. This will make maintenance easier and improve collaboration with other developers.
- Stay Up to Date: The Business Central ecosystem and the AL language are constantly evolving. Join developer communities, attend webinars, and follow official blogs to stay current with the latest updates and best practices.
- Optimize Performance: Make sure your code is optimized for performance. Avoid unnecessary loops and use indexes efficiently to improve query speed.
- Test and Debug: Perform thorough testing of your developments to identify and correct errors. Use VSCode’s debugging tools to analyze and resolve issues in your code.
- Collaborate and Share Knowledge: Work as a team and share your expertise with other developers. Collaboration and the exchange of ideas can lead to more innovative and efficient solutions.
Mastering the AL language and applying these tips can help you develop robust and efficient solutions in Dynamics 365 Business Central, enhancing productivity and customer satisfaction.
Conclusion on Time Calculations in Navision (Dynamics NAV) with AL Language

We have explored how to perform time calculations in Navision using the AL language through practical examples.
From subtracting and adding time values to calculating differences in minutes, these techniques are essential for optimizing time management in your business projects.
By mastering these calculations, you can significantly improve your company's efficiency and productivity, ensuring that processes run more smoothly and accurately.
We encourage you to adapt and expand these examples according to the specific needs of your projects.
If you have any questions or need more information, feel free to contact us.
We are here to help you achieve your goals.