{"title":"Time data type","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/time/time-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/time/time-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/time/time-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":"Denotes a time ranging from 00:00:00.000 to 23:59:59.999.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Instance methods","slug":"instance-methods","at":165,"chars":1333},{"level":2,"title":"SQL Server","slug":"sql-server","at":1498,"chars":413},{"level":2,"title":"Comparing time values","slug":"comparing-time-values","at":1911,"chars":1447},{"level":2,"title":"Related information","slug":"related-information","at":3358,"chars":117}],"text":"> Version: _Available or changed with runtime version 1.0._\nDenotes a time ranging from 00:00:00.000 to 23:59:59.999. An undefined or blank time is specified by 0T.\n## Instance methods\nThe following methods are available on instances of the Time data type.\nMethod name|Description\ntime-hour-method|Gets the hour component of the time represented by this instance.\ntime-millisecond-method|Gets the milliseconds component of the time represented by this instance.\ntime-minute-method|Gets the minute component of the time represented by this instance.\ntime-second-method|Gets the seconds component of the time represented by this instance.\nToText([Boolean])<time-totext-method>|Converts the value to a text. Equivalent to calling Format(value, 0, 0).\nThe displayed text format of the time is determined by your Regional and Language Options in Windows.\nThe following are examples of valid assignments of times to a Time variable MyTime. Time must be set by specifying hours, minutes, and seconds. Milliseconds are optional.\n```al\nMyTime := 0T;\nMyTime := 115900T;\nMessage(Format(MyTime));\nMyTime := 115934T;\nMessage(Format(MyTime));\nMyTime := 115934.444T;\nMessage(Format(MyTime));\nMyTime := 235900T;\nMessage(Format(MyTime));\nMyTime := 030000T;\nMessage(Format(MyTime));\n```\nThe following shows what the message windows display accordingly on a computer with the regional format set to English (United States) for the syntax examples above.\n11:59:00 AM\n11:59:34 AM\n11:59:34.444 AM\n11:59:00 PM\n3:00:00 AM\n## SQL Server\nMicrosoft SQL Server stores information about both date and time in columns of the datetime type. Business Central uses only the time part and inserts a constant value for the date: 01-01-1754.\nThe Business Central undefined time is represented by the same value as an undefined date. The undefined date is represented by the earliest valid datetime in SQL Server, which is 01-01-1753 00:00:00:000.\n## Comparing time values\nThe comparison of time values doesn't work if you compare the time value before writing to the database with the time value that was written to the database.\nThe cause of the problem is that in Business Central DateTime and Time values are rounded by SQL Server (see https://learn.microsoft.com/sql/t-sql/data-types/datetime-transact-sql). This means that a DateTime or Time value can change just because it was written to the database, and the comparison with the original value then runs on error.\nFor comparison of two time values, a procedure like the following should be used:\n```al\nprocedure CompareTime(TimeA: Time; TimeB: Time): Integer\nbegin\n    // Compares the specified Time values for equality within a small threshold.\n    // Returns 1 if TimeA > TimeB, -1 if TimeB > TimeA, and 0 if they are equal.\n\n    // The threshold must be used to compensate for the varying levels of precision\n    // when storing DateTime values. An example of this is the T-SQL datetime type,\n    // which has a precision that goes down to the nearest 0, 3, or 7 milliseconds.\n\n    case true of\n        TimeA = TimeB:\n            exit(0);\n        TimeA = 0T:\n            exit(-1);\n        TimeB = 0T:\n            exit(1);\n        Abs(TimeA - TimeB) < 10:\n            exit(0);\n        Abs(TimeA - TimeB) = 86399999:\n            exit(0);\n        TimeA > TimeB:\n            exit(1);\n        else\n            exit(-1);\n    end;\nend;\n```\n## Related information\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}