---
title: Data Types and Formatting
description: Looking at data and how we can display the same value in multiple ways
---

Last week, we read an article called Introduction to Data Types and used it to create the databases in the SQL server. Those datatype concepts are very much alive and well here also. For example, what is the difference between 123456789 and 123,456,789? To a human, nothing. To a computer, almost everything. Let's look at it.
```javascript
123456789 is a number
123,456,789 is a string
 ```

 Remember that numbers can ONLY have numerals, a decimal point and perhaps a positive or negative sign (depending on if it's an integer, a float, signed or unsigned).

There are some computer programs that are very strictly typed. That means that whenever you are talking about number, dates, or other data types, you need to specifically say that THIS IS A NUMBER. THIS IS A DATE. BoxLang really does try to make things as straightforward as possible (one of the reasons I use it). Therefore, you don't need to announce to your application that you are now dealing with a number, the program gives it its best guess and, for the most part, it does pretty well. However, even if you don't SAY what type of data it is, the program still has to treat your information as if it is a particular datatype. Therefore, if you try to add two numbers #5+3#, you will get 8. If you try to add a string and a number you will get something else. See:

```html
#5+3# = 8
#'fish' + 3# = Can't cast [fish] to a Number.
```

In this case, we told it to mathematically add a string ("fish") to a number (3) which is pretty much impossible and it says so. SOOOOO, does that mean that we are forever, forced to look at numbers like 6234798723847932 with no commas, dollar signs or any other human readable features? Of course it doesn't. This brings up the concept of formatters. There is, or can be, a difference between the underlying type of data and how it is presented on the screen. BoxLang (and other languages) does this with what are called "formatters". BoxLang has several. We're going to look at two of them.

## Number Formatters
Let's look at our example: 123456789. A nine digit, hard for humans to read, number. With a Number formatter we can specify that this number should have commas and, just for fun, a dollar sign. We can do that like this: #Numberformat(123456789,"$,")# and we get $123,456,789. We told the formatter to put in a $ and a , in the default places and it did. The second part of this is called a "Mask". The point here isn't that you need to learn the exact syntax for the NumberFormat Mask since it's in the BoxLang Documentation here:https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/format/numberformat but that you know the concept.

## Date Formatters
Dates are another of those things that are inherently human readable. What does a date look like to the computer? Like this: ```{ts '2022-02-06 20:18:11'}``` . That particular format is called a TimeStamp. You can read it and once you get past the {} and the quotes you can see the date and the time in 24hr format including the hours, minutes and seconds. So how do you get the date to appear on the screen? This is done by calling a BoxLang function. 

A function is a list of instructions that you can give to a computer or programming language to perform. Most functions, at least in BoxLang, have names and can be referenced simply by calling its name. In this case we are going to look at a common function to get the current date and time as a date and is called now(). It's very difficult so pay attention: To make it work you type ```#now()#```. Whew! Complex, right! Of course it needs to be inside a ```<bx:output>``` component but you already knew that ;) Whenever you see "()" it almost always means that there is a function being called. The parentheses are important for reasons we will look at later .

!!! question "Using now()"
    In the exercise folders, create a page called "MyDate.cfm". In the body tag, add ```<bx:output>#now()#</bx:output>```. Open the page in a browser and you should see the current date and time as a time stamp.

However, it's usually not a good idea to make your audience work very hard for seemingly simple things like the time, so let's look at the Date Formatter.

 The syntax is very similar to the Number Formatter in that is it looks like this: ```DateFormat(Date,"mask")```. The trick is to then know what goes into making the mask. The documentation at (https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dateformat) has a list of the elements of a mask. For example, to make the common date notation for the US, you would type #dateformat(now(),"mm/dd/yyyy")# and it appears like this: 02/06/2022

!!! question "Formatting Dates"
    Open up your MyDate.bxm page again. On the next 5 lines, use different masks (find them on the link above) to make the date appear differently.
