{"id":"4LVPkugTGvE","title":"Lesson 6: Primitive Data Types","description":"This is an overview of the basic data types in Daml, a strongly typed language. We covers numbers, text, booleans, dates, and times, and provides examples of how to use them in Daml. We also explains the differences between numeric, decimal, and big numeric data types for handling large numbers. Additionally, the video covers the show function for converting data types to readable text and the setTime and subTime functions for working with dates and times. \n\n00:28 Numbers\n02:09 Text and Booleans\n02:19 Dates and Time\n05:17 Review\n\nFor a better learning experience, sign up and enroll in this free course at: https://daml.talentlms.com/plus/catalog/courses/141","channel_name":"Digital Asset Training","published_at":"2025-02-19T00:00:00.000Z","thumbnail_url":"https://i.ytimg.com/vi/4LVPkugTGvE/hqdefault.jpg","transcript_text":"Daml is strongly typed, which makes it easy to find issues and errors in your code early. Let's look at a few basic or primitive data types. In Daml, there are a number of other data types, but here we'll look at numbers, text, booleans, and dates. Let's start with a module called DataTypeExample that includes a test script. In this script we have a \"do block\" starting with Let. Let allows us to bind values to variables locally, inside a block. So in this let statement we're declaring a variable with the name, amount, and data type int. We then assign a value of 10 to it and can use the script result feature to print its value. Int is short for integer, uses 64-bit, and supports numbers up to plus or minus nine quintillion. When you're dealing with very large numbers, you can use underscores to separate out blocks for readability. The second type is numeric. The variable N specifies the scale that you would like to use, and it could be anywhere from zero to 37 decimal digits. A closely related type is decimal in which N is preset to 10. Let's look at some code to understand how these data types are used. In this code the data type for amount is changed to numeric five, which means a number with five digits after the decimal. If we add more digits after the decimal, we'll see an error. Note that the total number of digits before and after the decimal can't be more than 38 for numeric numbers. If we change the type to decimal, we see that the error goes away. The difference between numeric and decimal is that the decimal data type has a set maximum number of digits of 10. If you need to deal with more than 38 decimal digits, including both before and after the decimal point, then the option is big numeric, which can take up to two, raised to the power of 15 digits before the decimal and the same number of digits after the decimal. That's a big number. It's important to note that this type of numeric variable is only intended for intermediate computation and should be rounded and converted to numeric N if it needs to be. The next two data types are probably what you've seen in other languages. Text, which is a string enclosed with quotes and bool, which is a boolean value, either true or false. So the last data types we'll look at here are date and time. A date value in Daml uses year, month, day format. We can create a date with the function date, notice it starts with a lower d, by passing the year, month, and day we want to. In a similar way, there is a time data type, which represents time with microsecond precision. There's a function called \"time\" with a small T that takes date, hour, minute , and second to return a time value. Finally, there's a \"realTime\" data type that represents the time difference between two time values. But before we can work with these data types, we need to import the date and time modules from the Daml standard library. Let's look at some code to unpack these data types a bit. In this script, we start with a function called getTime, which gets the ledger time when using Daml Studio in Visual Studio Code. This function creates a time in the 1970s. That's because the ledger is not actually active and getting updated from the system time. We'll set a variable dateOfBirth, of type date, and assign the date as January 2nd, 2000. The timeOfBirth is assigned the time on date of. As 15, 30, 10, or as hours, minutes and seconds, meaning 3:30 PM and 10 seconds. Next, we have age one as relTime, which is a time for relative time. Age one is calculated using sub time function. That subtracts timeOfBirth from now1. You can see in the output that age1 is showing as a negative number because now1 is before dateOfBirth. Finally, in the three debug statements, we see the three values printed. There are two points to note in these debug statements. First, the debug statements have some text labels such as \"DOB\" and \"Time\" followed by angle brackets as the string concatenation operator. This allows us to print a series of strings together. You'll see this operator a lot when we use debug statements so we can give it a more meaningful label. And second, there's a keyword \"show\" before the variable name. Show is a function that takes a value of a certain data type and then converts it into readable text, kind of like a .toString method in other languages. Since we're using the concatenation operator, we need to have both arguments as strings and need to use the show function to convert the date value to a string. Continuing from the previous example, we can use the setTime function to set the time to the correct time, and then use relTime to calculate the age using the subTime function. So here we first define a variable today and set it to the 10th of January, 2023, and then the time as 10:30 AM. We then use the setTime function using now2. And when we calculate age2 using subTime, it shows the correct age as of today. So let's review what we've gone over. Daml data types, handle numbers, texts, and boolean values. We looked at three data types to handle date and time. This is all to prepare us for a few more primitive data types in Daml that are specific to smart contracts such as party and contract id.","transcript_synced_at":"2026-10-26T04:03:25.746Z","segments":[{"start_seconds":0,"text":"Daml is strongly typed, which makes it easy to find issues and errors in your code early. Let's look at a few basic or primitive data types.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=0s"},{"start_seconds":7,"text":"In Daml, there are a number of other data types, but here we'll look at numbers, text, booleans, and dates.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=7s"},{"start_seconds":16,"text":"Let's start with a module called DataTypeExample that includes a test script. In this script we have a \"do block\" starting with Let.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=16s"},{"start_seconds":24,"text":"Let allows us to bind values to variables locally, inside a block.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=24s"},{"start_seconds":28,"text":"So in this let statement we're declaring a variable with the name, amount, and data type int.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=28s"},{"start_seconds":34,"text":"We then assign a value of 10 to it and can use the script result feature to print its value.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=34s"},{"start_seconds":40,"text":"Int is short for integer, uses 64-bit, and supports numbers up to plus or minus nine quintillion.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=40s"},{"start_seconds":47,"text":"When you're dealing with very large numbers, you can use underscores to separate out blocks for readability. The second type is numeric.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=47s"},{"start_seconds":56,"text":"The variable N specifies the scale that you would like to use, and it could be anywhere from zero to 37 decimal digits.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=56s"},{"start_seconds":63,"text":"A closely related type is decimal in which N is preset to 10. Let's look at some code to understand how these data types are used.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=63s"},{"start_seconds":72,"text":"In this code the data type for amount is changed to numeric five, which means a number with five digits after the decimal. If we add more digits after the decimal, we'll see an error.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=72s"},{"start_seconds":83,"text":"Note that the total number of digits before and after the decimal can't be more than 38 for numeric numbers. If we change the type to decimal, we see that the error goes away.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=83s"},{"start_seconds":94,"text":"The difference between numeric and decimal is that the decimal data type has a set maximum number of digits of 10.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=94s"},{"start_seconds":101,"text":"If you need to deal with more than 38 decimal digits, including both before and after the decimal point, then the option is big numeric, which can take","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=101s"},{"start_seconds":109,"text":"up to two, raised to the power of 15 digits before the decimal and the same number of digits after the decimal. That's a big number.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=109s"},{"start_seconds":119,"text":"It's important to note that this type of numeric variable is only intended for intermediate computation and should be rounded and converted to numeric N if it needs to be.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=119s"},{"start_seconds":129,"text":"The next two data types are probably what you've seen in other languages.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=129s"},{"start_seconds":132,"text":"Text, which is a string enclosed with quotes and bool, which is a boolean value, either true or false. So the last data types we'll look at here are date and time.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=132s"},{"start_seconds":143,"text":"A date value in Daml uses year, month, day format.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=143s"},{"start_seconds":148,"text":"We can create a date with the function date, notice it starts with a lower d, by passing the year, month, and day we want to.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=148s"},{"start_seconds":156,"text":"In a similar way, there is a time data type, which represents time with microsecond precision.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=156s"},{"start_seconds":163,"text":"There's a function called \"time\" with a small T that takes date, hour, minute , and second to return a time value.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=163s"},{"start_seconds":170,"text":"Finally, there's a \"realTime\" data type that represents the time difference between two time values.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=170s"},{"start_seconds":177,"text":"But before we can work with these data types, we need to import the date and time modules from the Daml standard library. Let's look at some code to unpack these data types a bit.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=177s"},{"start_seconds":187,"text":"In this script, we start with a function called getTime, which gets the ledger time when using Daml Studio in Visual Studio Code.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=187s"},{"start_seconds":194,"text":"This function creates a time in the 1970s.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=194s"},{"start_seconds":198,"text":"That's because the ledger is not actually active and getting updated from the system time.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=198s"},{"start_seconds":203,"text":"We'll set a variable dateOfBirth, of type date, and assign the date as January 2nd, 2000. The timeOfBirth is assigned the time on date of.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=203s"},{"start_seconds":212,"text":"As 15, 30, 10, or as hours, minutes and seconds, meaning 3:30 PM and 10 seconds.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=212s"},{"start_seconds":219,"text":"Next, we have age one as relTime, which is a time for relative time. Age one is calculated using sub time function.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=219s"},{"start_seconds":228,"text":"That subtracts timeOfBirth from now1.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=228s"},{"start_seconds":232,"text":"You can see in the output that age1 is showing as a negative number because now1 is before dateOfBirth.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=232s"},{"start_seconds":239,"text":"Finally, in the three debug statements, we see the three values printed. There are two points to note in these debug statements.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=239s"},{"start_seconds":245,"text":"First, the debug statements have some text labels such as \"DOB\" and \"Time\" followed by angle brackets as the string concatenation operator.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=245s"},{"start_seconds":255,"text":"This allows us to print a series of strings together.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=255s"},{"start_seconds":259,"text":"You'll see this operator a lot when we use debug statements so we can give it a more meaningful label. And second, there's a keyword \"show\" before the variable name.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=259s"},{"start_seconds":270,"text":"Show is a function that takes a value of a certain data type and then converts it into readable text, kind of like a .toString method in other languages.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=270s"},{"start_seconds":278,"text":"Since we're using the concatenation operator, we need to have both arguments as strings and need to use the show function to convert the date value to a string.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=278s"},{"start_seconds":287,"text":"Continuing from the previous example, we can use the setTime function to set the time to the correct time, and then use relTime to calculate the age using the subTime function.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=287s"},{"start_seconds":297,"text":"So here we first define a variable today and set it to the 10th of January, 2023, and then the time as 10:30 AM.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=297s"},{"start_seconds":307,"text":"We then use the setTime function using now2. And when we calculate age2 using subTime, it shows the correct age as of today.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=307s"},{"start_seconds":317,"text":"So let's review what we've gone over. Daml data types, handle numbers, texts, and boolean values. We looked at three data types to handle date and time.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=317s"},{"start_seconds":328,"text":"This is all to prepare us for a few more primitive data types in Daml that are specific to smart contracts such as party and contract id.","url":"https://www.youtube.com/watch?v=4LVPkugTGvE&t=328s"}],"youtube_url":"https://youtube.com/watch?v=4LVPkugTGvE","url":"https://ccpedia.xyz/videos/4LVPkugTGvE"}