{"title":"Duration data type","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/duration/duration-data-type/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/duration/duration-data-type, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/duration/duration-data-type","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Represents the difference between two DateTimes.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Instance methods","slug":"instance-methods","at":240,"chars":441},{"level":2,"title":"Example 1","slug":"example-1","at":681,"chars":632},{"level":2,"title":"Example 2","slug":"example-2","at":1313,"chars":249},{"level":2,"title":"Related information","slug":"related-information","at":1562,"chars":117}],"text":"> Version: _Available or changed with runtime version 1.0._\nRepresents the difference between two DateTimes. This value can be negative. It is stored as a 64-bit integer. The integer value is the number of milliseconds during the duration.\n## Instance methods\nThe following methods are available on instances of the Duration data type.\nMethod name|Description\nToText([Boolean])<duration-totext-method>|Converts the value to a text. Equivalent to calling Format(value, 0, 0).\nThe following are examples of durations:\nDateTime-DateTime=Duration\nDateTime-Duration=DateTime\nDateTime+Duration=DateTime\nThe value of the Duration data type can also be explicitly defined in milliseconds.\n## Example 1\nThis example shows how to calculate the difference between two DateTimes. This example is run on a computer with the Current Format in the Regional and Language Options set to English (United States).\n```al\nvar\n    DateTime1: DateTime;\n    DateTime2: DateTime;\n    Duration: Duration;\nbegin\n    DateTime1 := CreateDateTime(20090101D, 080000T); // January 1, 2009 at 08:00:00 AM\n    DateTime2 := CreateDateTime(20090505D, 133001T); // May 5, 2009 at 1:30:01 PM\n    Duration := DateTime2 - DateTime1;\n    Message(Format(Duration));\nend;\n```\nThe message window displays the following:\n124 days 4 hours 30 minutes 1 second\n## Example 2\nThe following example shows how to specify the duration of a timeout in milliseconds.\n```al\nprocedure GetDefaultTimeout(): Duration\nvar\n     Timeout: Duration;\nbegin\n    Timeout := 1000 * 60 * 60; // One hour\n    exit(Timeout);\nend\n```\n## Related information\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}