

# Working with Numerical Data
<a name="NumericalData"></a>

**Topics**
+ [Negative Numbers Offsets](NegativeNumbersOffsets.md)
+ [Zero Padding](ZeroPadding.md)
+ [Dates](Dates.md)

Amazon SimpleDB is a schema-less data store and everything is stored as a UTF-8 string value. This provides application designers with the flexibility of enforcing data restrictions at the application layer without the data store enforcing constraints.

All comparisons are performed lexicographically. As a result, we highly recommend that you use negative number offsets, zero padding, and store dates in an appropriate format.

# Negative Numbers Offsets
<a name="NegativeNumbersOffsets"></a>

When choosing a numerical range, ensure that every number is positive. To do this, choose an offset that is larger than the smallest expected negative number in your data set. For example, if the smallest expected number in your data set is -12,000, choosing offset = 100,000 might be safe.

The following is a sample original data set.

```
14.58, -12536.791, 20071109, 655378.34, -23
```

If you apply an offset of 100,000, the following is the resulting data set.

```
100014.58, 87463.209, 20171109, 755378.34, 99977
```

# Zero Padding
<a name="ZeroPadding"></a>

After all the numbers in a data set are positive, ensure they are properly represented for lexicographical comparisons. For example, the string "10" comes before "2" in lexicographical order. If we zero pad the numbers to five digits, "00002" comes before "00010" and are compared correctly. Additionally, the offset is valid for numbers up to 5 digits and future numbers such as 00402 and 02987 are properly represented in this scheme.

To determine the right number of digits for zero padding, determine the largest number in your data set (accounting for negative number conversions), determine the offset number (maximum number of digits for that number without a decimal point), and convert all your numbers by appending zeros to them until they match the digit length of the offset number.

The following is sample data set with an offset applied.

```
100014.58, 87463.209, 20171109, 755378.34, 99977
```

If you zero pad the data set as well, the following is the resulting data set.

```
00100014.58, 00087463.209, 20171109, 00755378.34, 00099977
```

From this result set, the original query `'attribute' > '500'` is now `'attribute' > '00100500'`.

# Dates
<a name="Dates"></a>

To convert dates to strings, we recommend following the ISO 8601 format, which supports lexicographical order comparisons.

The following table describes formats for representing date-time values with differing degrees of granularity. You must use components exactly as they are shown here and with exactly this punctuation. Note that the "T" appears literally in the string, to indicate the beginning of the time element, as is specified in ISO 8601. 


| Granularity | String | 
| --- | --- | 
| Year |  YYYY  (e.g., 1997)  | 
| Year and month |  YYYY-MM  (e.g., 1997-07)  | 
| Complete date |  YYYY-MM-DD (e.g., 1997-07-16)  | 
| Complete date plus hours and minutes |  YYYY-MM-DDThh:mmTZD  (e.g., 1997-07-16T19:20\$101:00)  | 
| Complete date plus hours, minutes and seconds |  YYYY-MM-DDThh:mm:ssTZD  (e.g., 1997-07-16T19:20:30\$101:00)  | 
| Complete date plus hours, minutes, seconds and a decimal fraction of a second |  YYYY-MM-DDThh:mm:ss.sTZD  (e.g., 1997-07-16T19:20:30.45\$101:00)  | 