Data type date excel

In a Data Model, each column has an associated data type that specifies the type of data the column can hold: whole numbers, decimal numbers, text, monetary data, dates and times, and so on. Data type also determines what kinds of operations you can do on the column, and how much memory it takes to store the values in the column.

If you’re using the Power Pivot add-in, you can change a column’s data type. You might need to do this if a date column was imported as a string, but you need it to be something else. For more information, see Set the data type of a column in Power Pivot.

In this article

  • Summary of data types

    • Table Data Type

  • Implicit and explicit data type conversion in DAX formulas

    • Table of Implicit Data Conversions

      • Addition (+)

      • Subtraction (-)

      • Multiplication (*)

      • Division (/)

      • Comparison operators

  • Handling blanks, empty strings, and zero values

Summary of data types

The following table lists data types supported in a Data Model. When you import data or use a value in a formula, even if the original data source contains a different data type, the data is converted to one of these data types. Values that result from formulas also use these data types.

Data type in Excel

Data type in DAX

Description

Whole Number

A 64 bit (eight-bytes) integer value 1, 2

Numbers that have no decimal places. Integers can be positive or negative numbers, but must be whole numbers between -9,223,372,036,854,775,808 (-2^63) and 9,223,372,036,854,775,807 (2^63-1).

Decimal Number

A 64 bit (eight-bytes) real number 1, 2

Real numbers are numbers that can have decimal places. Real numbers cover a wide range of values:

Negative values from -1.79E +308 through -2.23E -308

Zero

Positive values from 2.23E -308 through 1.79E + 308

However, the number of significant digits is limited to 15 decimal digits.

TRUE/FALSE

Boolean

Either a True or False value.

Text

String

A Unicode character data string. Can be strings, numbers or dates represented in a text format.

Maximum string length is 268,435,456 Unicode characters (256 mega characters) or 536,870,912 bytes.

Date

Date/time

Dates and times in an accepted date-time representation.

Valid dates are all dates after January 1, 1900.

Currency

Currency

Currency data type allows values between -922,337,203,685,477.5808 to 922,337,203,685,477.5807 with four decimal digits of fixed precision.

N/A

Blank

A blank is a data type in DAX that represents and replaces SQL nulls. You can create a blank by using the BLANK function, and test for blanks by using the logical function, ISBLANK.

1 DAX formulas do not support data types smaller than those listed in the table.

2 If you try to import data that has very large numeric values, import might fail with the following error:

In-memory database error: The ‘<column name>’ column of the ‘<table name>’ table contains a value, ‘1.7976931348623157e+308’, which is not supported. The operation has been cancelled.

This error occurs because Power Pivot uses that value to represent nulls. The values in the following list are synonyms for the null value:

Value

9223372036854775807

-9223372036854775808

1.7976931348623158e+308

2.2250738585072014e-308

Remove the value from your data and try importing again.

Table Data Type

DAX uses a table data type in many functions, such as aggregations and time intelligence calculations. Some functions require a reference to a table; other functions return a table that can then be used as input to other functions. In some functions that require a table as input, you can specify an expression that evaluates to a table; for some functions, a reference to a base table is required. For information about the requirements of specific functions, see DAX Function Reference.

Implicit and explicit data type conversion in DAX formulas

Each DAX function has specific requirements as to the types of data that are used as inputs and outputs. For example, some functions require integers for some arguments and dates for others; other functions require text or tables.

If the data in the column you specify as an argument is incompatible with the data type required by the function, DAX in many cases will return an error. However, wherever possible DAX will attempt to implicitly convert the data to the required data type. For example:

  • You can type a date as a string, and DAX will parse the string and attempt to cast it as one of the Windows date and time formats.

  • You can add TRUE + 1 and get the result 2, because TRUE is implicitly converted to the number 1 and the operation 1+1 is performed.

  • If you add values in two columns, and one value happens to be represented as text («12») and the other as a number (12), DAX implicitly converts the string to a number and then does the addition for a numeric result. The following expression returns 44: = «22» + 22

  • If you attempt to concatenate two numbers, Excel will present them as strings and then concatenate. The following expression returns «1234»: = 12 & 34

The following table summarizes the implicit data type conversions that are performed in formulas. Excel performs implicit conversions whenever possible, as required by the specified operation.

Table of Implicit Data Conversions

The type of conversion that is performed is determined by the operator, which casts the values it requires before performing the requested operation. These tables list the operators, and indicate the conversion that is performed on each data type in the column when it is paired with the data type in the intersecting row.

Note: Text data types are not included in these tables. When a number is represented as in a text format, in some cases Power Pivot will attempt to determine the number type and represent it as a number.

Addition (+)

Operator (+)

INTEGER

CURRENCY

REAL

Date/time

INTEGER

INTEGER

CURRENCY

REAL

Date/time

CURRENCY

CURRENCY

CURRENCY

REAL

Date/time

REAL

REAL

REAL

REAL

Date/time

Date/time

Date/time

Date/time

Date/time

Date/time

For example, if a real number is used in an addition operation in combination with currency data, both values are converted to REAL, and the result is returned as REAL.

Subtraction (-)

In the following table the row header is the minuend (left side) and the column header is the subtrahend (right side).

Operator (-)

INTEGER

CURRENCY

REAL

Date/time

INTEGER

INTEGER

CURRENCY

REAL

REAL

CURRENCY

CURRENCY

CURRENCY

REAL

REAL

REAL

REAL

REAL

REAL

REAL

Date/time

Date/time

Date/time

Date/time

Date/time

For example, if a date is used in a subtraction operation with any other data type, both values are converted to dates, and the return value is also a date.

Note: Data models also supports the unary operator, — (negative), but this operator does not change the data type of the operand.

Multiplication (*)

Operator (*)

INTEGER

CURRENCY

REAL

Date/time

INTEGER

INTEGER

CURRENCY

REAL

INTEGER

CURRENCY

CURRENCY

REAL

CURRENCY

CURRENCY

REAL

REAL

CURRENCY

REAL

REAL

For example, if an integer is combined with a real number in a multiplication operation, both numbers are converted to real numbers, and the return value is also REAL.

Division (/)

In the following table the row header is the numerator and the column header is the denominator.

Operator (/)

(Row/Column)

INTEGER

CURRENCY

REAL

Date/time

INTEGER

REAL

CURRENCY

REAL

REAL

CURRENCY

CURRENCY

REAL

CURRENCY

REAL

REAL

REAL

REAL

REAL

REAL

Date/time

REAL

REAL

REAL

REAL

For example, if an integer is combined with a currency value in a division operation, both values are converted to real numbers, and the result is also a real number.

Comparison operators

In comparison expressions Boolean values are considered greater than string values and string values are considered greater than numeric or date/time values; numbers and date/time values are considered to have the same rank. No implicit conversions are performed for Boolean or string values; BLANK or a blank value is converted to 0/»»/false depending on the data type of the other compared value.

The following DAX expressions illustrate this behavior:

=IF(FALSE()>»true»,»Expression is true», «Expression is false»), returns «Expression is true»

=IF(«12″>12,»Expression is true», «Expression is false»), returns «Expression is true».

=IF(«12″=12,»Expression is true», «Expression is false»), returns «Expression is false»

Conversions are performed implicitly for numeric or date/time types as described in the following table:

Comparison Operator

INTEGER

CURRENCY

REAL

Date/time

INTEGER

INTEGER

CURRENCY

REAL

REAL

CURRENCY

CURRENCY

CURRENCY

REAL

REAL

REAL

REAL

REAL

REAL

REAL

Date/time

REAL

REAL

REAL

Date/time

Top of Page

Handling blanks, empty strings, and zero values

In DAX, a null, blank value, empty cell, or a missing value are all represented by the same new value type, a BLANK. You can also generate blanks by using the BLANK function, or test for blanks by using the ISBLANK function.

How blanks are handled in operations, such as addition or concatenation, depends on the individual function. The following table summarizes the differences between DAX and Microsoft Excel formulas, in the way that blanks are handled.

Expression

DAX

Excel

BLANK + BLANK

BLANK

0 (zero)

BLANK +5

5

5

BLANK * 5

BLANK

0 (zero)

5/BLANK

Infinity

Error

0/BLANK

NaN

Error

BLANK/BLANK

BLANK

Error

FALSE OR BLANK

FALSE

FALSE

FALSE AND BLANK

FALSE

FALSE

TRUE OR BLANK

TRUE

TRUE

TRUE AND BLANK

FALSE

TRUE

BLANK OR BLANK

BLANK

Error

BLANK AND BLANK

BLANK

Error

For details on how a particular function or operator handles blanks, see the individual topics for each DAX function, in the section, DAX Function Reference.

Top of Page

Date Data Type in Excel VBA explained with syntax and examples. The Date VBA date type stores floating point numbers that represents date and time. We can store date, time or date and time. It has date range values from Jan 1, 0100 to December 31, 9999 and time values from 0:00:00 to 23:59:59. Date VBA data type doesn’t have literal type character and identifier type character, but it is enclosed with ‘#’. It occupies 8 bytes(64 bits) in memory.

Table of Contents:

  • Overview
  • Date VBA Data Type Syntax in Excel
  • Example on the Date VBA Data Type in Excel
  • Convert an Expression to Date VBA Data Type
  • Instructions to Run VBA Macro Code
  • Other Useful Resources

Let us see Data Type Date Syntax in Excel VBA.

Dim VariableName as Date

Where VariableName represents the name of the variable.
and Date represents the type of data.

Example on the Date VBA Data Type in Excel

Here is an example on the Date VBA Data Type in Excel.

Sub VBAF1_Date_DataType()
    
    'Integer Variable Declaration
    Dim dDate As Date
    Dim tTime As Date
    Dim dtDateTime As Date
    
    'Assign value to variable
    dDate = #1/1/2019#
    tTime = #1:01:01 AM#
    dtDateTime = #1/1/2019 1:01:01 AM#
    
    MsgBox "Date:  " & dDate & vbCrLf & "Time: " & tTime & vbCrLf & "DateTime: " & dtDateTime, vbInformation, "VBAF1"
     
End Sub

Here is the output screenshot of above macro.

VBA Date Data Type

Convert an Expression to Date VBA Data Type in Excel VBA

You can convert an expression to Date VBA data type using VBA CDate function. Click on the following link to learn about CDate function and complete tutorial and examples.

VBA CDate Function

VBA Data Types

Also read about all other data types.

VBA Data Types

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

Having represented this site as a technology blog with a focus on programming and software development, I find myself starting off with a tutorial on Excel basics instead. Somehow, I thought it was going to be more glamorous than this . . . This is driven by my need to prepare a training for my staff at work, and in keeping with the DRY principle (Don’t Repeat Yourself) I am killing two birds with one stone. Anyone hoping to read programming stuff is just going to have to wait . . .

This is part two of a multi-part series targeting entry-level users of Microsoft Excel. In the previous post, we discussed the basic structure of a spreadsheet, and covered the vary basics of using expressions (or formulas). There is a LOT more to that, but before we go any further, it is important to understand how Excel understands data.

I am about to be a little long-winded. Hopefully you will slog through anyway, unless you already have a solid grasp on this stuff. Let’s take a (really) broad look at some data basics, before we explore the data type definitions specific to Excel. Because this is a long post, here are some navigation aids:

The Broad View – Information Basics

  • What’s in a number? (numeric information)
  • Truth Be Told (logical information)
  • String Theory (Text information)

Details of Excel Data Types

  • The Logical Data Type
  • The Number Data Type
  • The Text Data Type
  • The Error Data Type

What’s in a number?

We humans don’t tend to think too hard about the type of data we are working with. We have evolved to be context-aware, and as we learn, we understand how to use MOST information within a particular context. For example, when we talk about our Social Security number, or our credit card number, we generally recognize either of those things as an identifier composed of numerical characters. We do not expect to be performing addition, multiplication, or other mathematical operations on these, even though semantically we still call them “numbers.” Further, both SSN’s and Credit Card account numbers might contain one or more leading zeros, or zeros at the rightmost end of the numerical sequence:

Example SSN: 001-11-1111

Never mind the dashes which make this SSN format behave emphatically NOT like a true number.

While most credit card companies assign a string of numerals as an account identifier (account number), other business entities might use a mixture of numerals and alphabetical characters to create account identifiers, which we still tend to refer to as “account numbers.” Again, while we think of the various account identifiers which (for some) rule our lives as “numbers”, we also tend to utilize them in a context more like a string of characters.

Contrast this with Social Security payments and/or credit card charges. These numbers represent numerical values which we contextually understand will be added to or subtracted from the current balance of our account. In a similar manner, the credit company will most likely perform a calculation (which, apropos of nothing whatsoever, would be represented by a formula) to determine how much interest to charge to our account. This amount would be calculated based upon our current balance (and a number of other factors), and then added to that balance for the current billing period. We intrinsically understand this, even though the actual math part may not be a part of our conscious thought stream.

In these cases, our human contextual ability allows us to (most of the time) use the right “numbers” in the correct and meaningful manner. Mentally, we all might play a quick mental arithmetic on our credit card account balance, subtracting the approximate amounts of our recent charges, before we decide to purchase that new 52″ HD television. When we whip out the plastic to punch the card number into the space on the Amazon website, we type in the set of numbers, recognizing that there is no numerical operation to be performed, other than making sure we type correctly.

[Back to Top]

Truth be Told . . .

On the other hand, we humans are nowhere near as good at evaluating a set of conditions and arriving at a concise logical value. We have to practice at this, and even then, our ability to inject that very same context can create flaws in our evaluation. We confuse our singular perceptions with absolutes. True logic is not relative. For example, on a very cold day here in Portland (say, 37 degrees F – yes, that would be “cold” here in the Pacific Northwest) one man might observe to another that it is “freezing out here” when in fact the temperature is well above the point at which liquid water changes state into its solid form. However, his companion is very likely to agree with him, or failing that, state that “yup, it’s cold out.”

Neither of these statements can be evaluated from a logical standpoint outside that of the observer, because they are relative statements. If an Inuit fresh from the North Slope of Alaska were to join the group, he would likely find the observations of the other two men absurd. To the Inuit, the actual outdoor temperature of, say, 37 degrees might feel nearly tropical. In fact, since “freezing” is technically defined as the point at which water turns to ice (32 degrees Fahrenheit, or 0 degrees Celsius), the only valid logical statement which could be made in this situation is that it is NOT, in fact, freezing outside.

As humans, we are accustomed to applying our personal, regional, and societal metrics in evaluating information. Our computers, however, and by extension the software which runs on them, are machines which deal in absolutes. To the machine, a statement which is not 100% true is FALSE. Numbers may be manipulated in meaningful mathematical ways, while arrangements of text cannot (or at least, not in the same manner as true numbers).

Despite some illusions built into our modern software (including Microsoft Excel) to the contrary, the computer does not understand context. The computer is very, very literal and will perform whatever action or calculation you request of it (unless, of course, the programmer built in a mechanism to prevent the operation from being carried out if certain conditions aren’t met) with no comprehension of the sensibility of the result.

At the very, very most basic level, TRUE and FALSE (in a technical sense, ON and OFF) are the only two things the computer hardware understands. After one delves down through several layers of software abstraction, one eventually runs into hardware which is binary in nature. Binary code is composed of ones and zeros, representing ON (one) and OFF (zero). We are not going to go into how all THAT works here. But its important to understand the literal nature of the machine, that the machine lacks ANY “context” beyond that supplied by the programmer, and that all of the information we work with in our user-friendly, usability-tested software interface has been heavily abstracted for our benefit.

There is an entire branch of mathematics devoted to logical analysis called Boolean Algebra. While we won’t be going into that in this article, an understanding of basic logical operations can lend itself well to some advanced spreadsheet features that will make you the envy of your friends, and the champion around the office. More in a bit.

[Back to Top]

String Theory

I am NOT about to embark on a discussion of theoretical physics.

I am going to talk about text. Like, words. This overly long post is constructed of words, in the English language, which I have typed in to the computer using my keyboard. I am currently creating this post using Windows Live Writer, a nifty blogging program which has abstracted away the need for me to understand all that goes into marking up my blog post with suitable HTML, creating an ftp connection, and uploading the content into the proper directories on the server so that it displays properly for you, the reader. I just type, and when I am done, I use mu mouse cursor to push an on-screen representation of a “button” that says “publish”. In the same manner, our software tends to abstract from us the need to understand what is really going un “under the hood” when we ask our machines to work with text. It appears to us, as end users, that the machine recognizes the strings of characters we type and manipulate, and works with text just as easily as it works with numbers.

Which is emphatically not true.

We’re not going to go into the how and why of it right now, but let’s just say that creating effective ways for our machines to handle input, display, formatting, and printing of text (not to mention standardization across platforms!) has been one of the major challenges of the PC era. Just to give you an idea, here are a couple of entertaining and informative articles by Joel Spolsky on the topic of character strings. It is not required reading for our purposes here, but you may find it informative:

  • Back to Basics (aka The Schlemiel the Painter Article)
  • The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Suffice it to say, it is important to be aware that text information lives in its own realm, even within the confines of our simple spreadsheet. Even more important, it is REALLY important for you, the reader, to be able to properly distinguish whether your spreadsheet should be treating the information in a cell as text, or something else. We’ll see why in the next post.

A final comment before we get into the nitty gritty. At a basic level, the text we take for granted on screen is regarded by our machine as a string of characters. These characters are actually ASCII or Unicode representations of what we actually see displayed. Because our words, sentences, and paragraphs (including whitespace and non-printing items such as carriage returns, tabs and other markup) are all composed of such character strings, we will often refer to text data as strings. In other words, in your travels, whether in Excel or some other application, mention is made of “String Parameter”, “String Data Type”, etc. you can generally substitute “text” for “string” and be just fine.

Ok. Now that we have the preliminaries out of the way, let’s look at how Microsoft Excel regards our data.

[Back to Top]

Data Types

Microsoft Excel recognizes four kinds of information: Logical values (TRUE or FALSE, also called Boolean values), Numerical values, Text values, and Error types. The four kinds of information are known, in technical parlance, as Data Types. What is important for you, the user, is to begin to think of your own information in this manner, and consider how the machine is going to use it.

Note that Excel will do the very best it can to figure out which of these types it THINKS you intend, once you complete typing into a cell and hit the enter key. For example, if you type a series of numerals, it assumes you intend a number type. If that series of numerals happens to begin with one or more zeros, Excel STILL thinks you intend to type a number, and eliminates those leading zeros. Likewise, if you type something the looks like a date, and contains valid numbers which can represent a valid date, Excel assumes you mean a number type again, formatted as a date.

You will learn more about this date stuff later in the post. However, be aware that Excel tries to help you in this manner. Most of the time, it works out. Sometimes, it doesn’t, and then you have to help Excel by telling it what you REALLY mean, explicitly.

The Logical Data Type

Logical values are either TRUE or FALSE.

In most cases, logical values will be present as the result of the evaluation of an expression or function. Essentially, a logical value represents the resolution of an expression indicating whether certain conditions have been met. For example:

The statement “1 is less than 2” is recognizable as a true statement. Another way to put that is:

1 < 2 = TRUE

When evaluating logical expressions, Excel recognizes the text TRUE as a logical (or boolean) value. Excel also treats the value 0 as false, and any other numerical value as true. For example, we can make a logical comparison about the values in two different cells by typing an expression:

If we add change one of the values, the expression will no longer return true:

Logical expressions are one of the more powerful tools Excel has to offer, and yet they are also some of the least utilized. We will devote an entire post to examining logical expressions in the near future.

[Back to Top]

The Number Data Type

Numerical values are, of course, numbers. This is more complex than it first appears, however. First of all, Excel stores all numbers as Double-Precision Floating Point values. I know. It’s a mouthful. For our purposes here, you can think of that as a decimal number, with room for a lot of decimal places if needed. Excel can store numbers as large as 1.79768 X 10308 and as small as 2.2250 X 10-308. These represent extremely large, and extremely small numbers, respectively.

The thing to remember here is that to Excel, all of the following are numbers: 15,000; 100; $50; $50.00; 75%; 0.5; 5.35E+04; and 12/25/2012.

What, you say? What was that last? Yes. To Excel, dates are also stored as plain old numbers. We’ll discuss THAT in a minute. For the moment, take a look at what you might type in or see displayed in a cell, vs. what excel is actually storing:

Visible in Cell 15,000 100 $50,000 $50.00 75% .5 5.35E+04 12/25/2012
Number Stored 15000 100 50000 50 0.75 0.5 53500 41268

While you are likely familiar with most of the numbers you see in the table above, some of you may not be familiar with the second from the right, known as Scientific E notation. Don’t worry about that right now. Scientific E notation is a a sort of shorthand for expressing very large (or very small) numbers The example above is trivial for the purpose of illustration. Trust me that the expression in the top cell is numerically equivalent to the number displayed in the cell below.

The important thing to remember is that numbers in Excel can be no more than 15 significant digits in length. This excludes zeros on either side of the number:

99999999999999900000 is 20 numerals, but only contains 15 significant digits; the fifteen “9’s” to the left of the five zeros. Likewise, .00000999999999999999 is also twenty decimal places, but contains only fifteen significant digits).

Numbers which are entered that contain more than 15 significant digits will be truncated. That is, significant digits will be lopped off the right-hand side and replaced with zeros. Note in the examples below, we can type in 19 significant digits (fourteen 9’s followed by 87654). Once we hit “Enter”, the significant digits in excess of 15 are truncated, leaving 0’s):

Dates and Times

Ok. Now on to that date thing. Dates and times are also stored as number types by Excel. Dates are stored as the number of days since the date 1/1/1900. In other words, January 1, 1900 is considered by Excel to be 1. Therefore, 1/2/1900 would be stored as 2, 1/3/1900 as 3, and so on. Note that Excel does not recognize dates BEFORE 1/1/1900. We’ll see why this matters in the next post about functions and expressions.

Excel treats Times as fractions of days. Since a day is 24 hours in length, then 1/4th of a day (0.25) would be 6 hours. Since each day begins at 0 hours and 24 hours later, Excel would store the date and time for 6:00 AM on 1/1/1900 as 1.25. As I type this sentence, it is 10:39 PM on August 9th, 2011. Therefore, Excel would store the current date and time as 40764.94384. That is, forty thousand three-hundred eighty-four and (roughly) 94/100ths days since 1/1/1900.

Values vs. Formats

The key thing about numbers in Excel is that you need to separate in your mind the number VALUE from the way it is DISPLAYED. The manner in which Excel displays a given numerical value within a cell is known as formatting. We will discuss different aspects of number formatting later, but for the moment, keep in mind that underneath whatever window dressing Excel provides in terms of formatting, the following are all representations of the same value (1.05):

1.05 = 1.050000 = $1.05 = 105% = 1/1/1900

Value in Cell Format Displayed in Cell
1.05 General 1.05
1.05 Number (6 digit decimal precision) 1.050000
1.05 Currency $1.05
1.05 Percent 105%
1.05 Date 1/1/1900

Likewise, these ALSO represent the same numerical value (.75):

.75 = $0.75 = 75% = 3/4 = 6:00:00 PM

Value in Cell Format Displayed in Cell
0.75 General 1.05
0.75 Currency (2 digit decimal precision) $0.75
0.75 Percent (1 digit decimal precision) 75.0%
0.75 Fraction 3/4
0.75 Time (hh:mm PM) 6:00:00 PM

We’ll cover the ins and outs of the various formatting choices in the next post. But be aware, that formatting can be tricky. Notice how, in the first example above, if we choose to format the value 1.05 as a Date, we get the displayed value of 1/1/1900. In a way, this is to be expected, since we learned that in Excel, the number 1 can be considered to represent 1/1/1900. But what about that .05 (five one-hundredths)? Well, this would actually represent 1/20th of 1 day (5/100ths reduces to 1/20th). But since we specified a date format which did not include the time as part of the format to display, we get only the date.

The value of a number is stored in the cell. Formatting determines how the number is displayed, and what level of precision is displayed. When using the value of the cell in calculations, the true value is used, not the displayed value!

We will see how this might matter in a later post. For now, we will move on the the Text data type.

[Back to Top]

The Text Data Type

As we discussed previously, Microsoft Excel regards test as strings of characters. The letters of the alphabet, numerical characters, symbols such as % and $, as well as spaces and tabs are all valid text. In cases where Excel cannot distinguish a value as either a number type, a logical type, or an error type, the value will be treated as text.

Excel will recognize a text string of up to 32,768 characters. However, only 1024 can be displayed in a cell.

Excel tries to be helpful, in that, as you enter information into a cell, the application attempts to determine what type of data you are entering and treat it accordingly. Most of the time this is fine, and helpful. However, sometimes it can trip us up. For example, we will return to the issue of leading zeros and account numbers. Lets say an account number begins with four zeros:00001234567891011. If we were to simply enter this string of numbers into a cell, excel will decide we are entering a number value, and will drop those leading zeros.

We can tell Excel to treat the data in a cell as text by pre-pending a single-quote character before the text we wish to enter, or by applying the text format to the cell through the cell formatting menu (which we will discuss in the next post).

Excel offers a host of text manipulation functions which we will examine in an upcoming post.

The Error Data Type

There are instances in which errors will occur when Excel evaluates the contents of a cell. For example, division by zero is mathematically undefined, and the machine cannot, by itself, resolve this error. It turns out the Excel has an Error type specifically for this instance, the #DIV/0! result.

The error type generally rears its ugly head due to problems with functions or formulas. The different error values Excel provides are listed in the following table, along with the meaning of the error:

Error Value Means Common Causes
#DIV/0 Division by zero You attempted to divide by a value of zero. A blank cell is treated as zero in mathematical operations.
#N/A No value Available Manually entered (and sometimes when data is imported) to indicate information not available
#NAME? Excel does not recognize the name of a list or range of cells The #NAME? error will result if you neglect to enclose text in quotes within a formula, or if you refer incorrectly to the name (address) of a cell or range of cells.
#NULL! Reference to a non-existent intersection between two cell ranges If you neglect to separate to cell ranges with a comma in certain function arguments, the #NULL! Error will result. Also if you refer to an intersection between two cell ranges which do not intersect.
#NUM! There is a problem with a number in a formula or result Passing an invalid argument to a function or formula, or a formula returns a number which is too large or too small to be represented in the cell.
#REF! Invalid Cell Reference You have deleted or pasted over a cell or cells referred to in a formula.
#VALUE! Invalid argument or operator in a function or formula Usually results from performing a mathematical operation with cells that contain text.

The short version of all this is that when you see that ugly hash symbol, you know you have a problem, usually in a formula. This reference will help you know where to begin looking for the problem.

OK. We’ve covered a lot of ground. In the next post we will take a closer look at formulas and some of the built-in functions Excel provides.

[Back to Top]

Summary

Understanding how Microsoft Excel interprets and handles different types of information is critical in constructing effective spreadsheets. Failure to properly anticipate how Excel will work with your data can potentially lead to calculation errors which are difficult to detect. In order to make the most effective use of expressions and formulas, and functions within Excel, an awareness of the various data types within the program will save time, frustration, and headaches.

  • It is important to consider that the computer does not have a contextual understanding of our information, beyond what the programmers built in.
  • Excel will attempt to determine the proper data type based on what you type into a cell. Sometimes you have to correct for this.
  • Excel recognized four types of data;
      • The Logical Type:
          • Indicates a value of TRUE or FALSE
          • A value of zero = FALSE; Any value other than zero = TRUE
      • The Number Type
          • All numbers are represented by a Double-Precision Floating Point value (big decimal numbers).
          • Numbers may contain up to 15 significant digits (exclude zeros on either side of the number).
          • Numbers may be as large as 1.79768 X 10308 or as small as 2.2250 X 10-308.
          • The number value is stored in the cell. Formatting determines how the number is displayed, and what level of precision is displayed. The precision of the value stored in the cell is not affected by the display format.
          • Dates and times are stored as number values.
              • The date 1/1/1900 is represented by the number 1, and successive dates are numbered as days since that date.
              • Times are stored as fractional parts of days. 1/4 = 1/4th of one day = 24/4 = 6 hours from the beginning of the day, or 6:00 AM.
      • The Text Type
          • Text is regarded by the computed as strings of characters
          • All characters can be stored as Text (A-Z, a-z, 0-9, !@#$ etc.)
          • Data which Excel cannot resolve to either a Number Type or a Logical Type is stored as Text.
          • Excel will recognize a text string of up to 32,768 characters. However, only 1024 can be displayed in a cell.
          • Inserting a single quote character as the first character in a cell will tell Excel to store the data in the cell as Text, even if it composed entirely of numerals.
      • The Error Type
          • The error type is returned when Excel encounters an error in evaluating the contents of a cell.
          • The Error Type generally occurs because of a problem in a formula.

Next: A Closer Look at Expressions and Formulas

In Excel, data type means the type of data which can be stored in an Excel Cell. Basically, there are three data types in Excel.

  • Numeric data
  • Text data
  • Date and Time data (internally stored as numbers)

Excel constantly monitors the data you type in Excel Cell and classifies it into above data types.

Another type which is not shown in the above list is Excel formula. Excel formulas are not constant data, but used to calculate results from constant data available in different Cells of Excel worksheets.

Numeric data

Numeric data stored in Excel Cells are used to build most of the formulas in Excel. There are two types of numeric data;

  • Numeric data : Numeric data is used to store quantities. Example — 500 sacks of Cement.
  • Date and Time : Date and Time data type is used to store Date and Time values. Excel stores Date and Time also as numbers internally. Click following links to learn more about different date systems in Excel and how does Excel stores time values.

Numeric data type in Excel is used to store different quantities, which can be later used for mathematical operations using Excel formulas.

In Excel (as of 2019), you can store numeric values in an Excel Cell, up to a precision of 15 digits. Let me explain what is the meaning of «15-digit precision«.

Refer below image. I am trying to enter a 20-digit numeric value inside Cell A1.

numeric-value-above-15-digits.jpg

You can see from the below image that once the Cell mode is changed from Enter mode to Ready mode, Excel has changed the last five digits (digits after 15) to 0.

numeric-value-above-15-digits-rounded.jpg

A 15-digit number is a very large number and the above explained limitation (15-digit precision) in Excel will not cause any serious problem in its real-time application.

Following table lists the largest and smallest of positive and negative number possible in Excel (as of 2019).

Largest or Smallest Numeric data
Largest positive number 9.9e+307
Smallest positive number 1e-307
Largest negative number -1e-307
Smallest negative number -9.9e+307

Excel numeric data type can have numeric characters (0 to 9) in Excel Cell. Apart from numeric characters (0 to 9), following special characters can also be used for different purposes.

Characters allowed in numeric data type Purpose
+ Positive symbol
Negative symbol
() Negative symbol
% Percentage symbol
. Decimal symbol
, Decimal symbol
E Exponential symbol
e Exponential symbol

Text data

In an Excel Cell, the text data consists of a combination of alphabet characters, numeric characters or special characters. The text data is also called as string data. In an Excel Cell, text data is aligned to the left-side of the Cell and numeric data is aligned to the right-side of the Cell.

Even if an Excel Cell contains numeric characters along with alphabet characters, Excel treats that data as text. The text data inside that Cell cannot be used for any mathematical formulas. If you try to perform any mathematical operation with text data in an Excel Cell, you may get #VALUE! error as the result.

If the text data in an Excel Cell is wider than the Cell width, the text data will spill-over the right-side Cells, if the right-side Cells are empty.

If any right-side empty Cell is filled later, Excel hide the spilled text before newly filled Cell to reveal it’s data.

From below image, you can see the text data in Cell A6 is spilled over right-side Cells, because the right-side Cells are empty.

excel-cell-text-data-spill.jpg

Once you have some data at a right-side Cell (in this case Cell C6), Excel stops the text spillage before the newly filled Cell to make the data inside the newly filled Cell visible.

excel-stop-cell-text-data-spill.jpg

Date and time

Date and time data is also stored internally as numeric value. Excel stores internally the date and time value as a number known as date-time serial number. Date and time data is also aligned to the right-side similar to numeric data. Data and time data type can be used to store a date value, time value or both. The date and time value can appear of different formats, based on how you format the Cell.

Date and time data can be used to store date, time or both. Remember to store the date value separated by proper date separator characters or /. Example, 05-12-2021 or 05/12/2021. If there is no proper separator, Excel will treat the value as text data, not as date time data.

Following image shows a date value stored in different formats

date-data-type-formats.jpg

As of Excel 2019, dates ranging from January 1, 1900 (date serial number 1) through December 31, 9999 (date serial number 2958465) are supported. If you have any date value beyond this range, Excel will display an unending hash (#) error inside Excel Cell.

Below screen shot shows a date beyond December 31, 9999 (date serial number 2958466). Refer below image to see the error generated by Excel.

excel-unsupported-date-error.jpg

Note that in US English, date is written using month/day/year format. But in some other parts of the world, date is written as day/month/year format. The difference in date format at different parts of the world is often confusing. For example; December 5, 2021 is written as 12/05/2021 in US English format, but as 05/12/2021 in India. In omnisecu.com Excel tutorials, I am using day/month/year format.

The separator character used to separate hour, minute and second in time is : (colon). If you want to use AM or PM with a time value, remember to keep one space between value and AM/PM. If there is no space, Excel will consider the value as text.

Following image shows a time value stored in different formats

time-data-type-formats.jpg

Note that special the date January 0, 1900 is used to represent the date, where time alone is entered. Visit following lessons to learn more about how Excel stores time values, and how Excel stores date and time values together.

Date Time LeadDates and times are two of the most common data types people work with in Excel, but they are also possibly the most frustrating to work with, especially if you are new to Excel and still learning. This is because Excel uses a serial number to represent the date instead of a proper month, day, or year, nevermind hours, minutes, or seconds. It’s made more complicated by the fact that dates are also days of the week, like Monday or Friday, even though Excel doesn’t explicitly store that information in the cells. Here is the definitive guide to working with dates and times in Excel…

How Excel Stores Dates

The source of most of the confusion around dates and times in Excel comes from the way that the program stores the information. You’d expect it to remember the month, the day, and the year for dates, but that’s not how it works…

Excel stores dates as a serial number that represents the number of days that have taken place since the beginning of the year 1900. This means that January 1, 1900 is really just a 1. January 2, 1900 is 2. By the time we get all the way to the present decade, the numbers have gotten pretty big… September 10, 2013 is stored as 41527.

Importantly, any date before January 1, 1900 is not recognized as a date in Excel. There are no “negative” date serial numbers on the number line.

It seems confusing, but it makes it a lot easier to add, subtract, and count days. A week from September 10, 2013 (September 17, 2013), is just 41527 + 7 days, or 41534.

How Excel Stores Times

Excel stores times using the exact same serial numbering format as with dates. Days start at midnight (12:00am or 0:00 hours). Since each hour is 1/24 of a day, it is represented as that decimal value: 0.041666…

That means that 9:00am (09:00 hours) on September 10, 2013 will be stored as 41527.375.

When a time is specified without a date, Excel stores it as if it occurred on January 0, 1900. In other words, 3:00pm (15:00 hours) is stored as 0.625. This can make doing math for time-only values (that have no date) challenging, since subtracting 6 hours (6:00)  from 3:00am (03:00 hours) will become negative and count as an error: 0.125 – 0.25 = -0.125, which is displayed as #########.

Minutes and seconds in Excel work the same way as hours…

A minute is 1/60 of an hour, which is 1/24 of a day, or 1/1440 of a day in total, which calculates to 0.00069444…

A second is 1/60 of an minute, which is 1/60 of an hour, which is 1/24 of a day, or 1/86400 of a day in total, which calculates to 0.00001157407…

Working with Dates and Times

DATE() and TIME()

Serial numbers aren’t all that intuitive to use. Fortunately, Excel has a set of functions to make it easier to find and use dates and times, starting with DATE and TIME. The syntax is as follows:

=DATE(yearmonthday)
=TIME(hoursminutesseconds)

For both functions, specify the year, month, and day, or hours, minutes, and seconds as numbers. For example, September 10, 2013 can be entered as:

=DATE(2013,9,10)

It will be stored as 41527, which means that it is technically storing 12:00am on September 10, 2013.

For times, 6:00pm (18:00 hours) can be entered as:

=TIME(18,0,0)

It will be stored as 0.75, which means that it is technically storing 6:00pm on January 0, 1900.

If we want to represent a specific time and date, we can add the two functions together. For example, 6:00pm (18:00 hours) on September 10, 2013 can be entered as:

=DATE(2013,9,10)+TIME(18,0,0)

It will be calculate as 41527.75, which means Excel is storing exactly the date we want…

Additional Date and Time Setting Functions

Excel has a few additional functions to make declaring dates easier.

TODAY()

The TODAY function always returns the current date’s serial number. The TODAY function is just entered as:

=TODAY()

This article was written at 6:30pm (18:30 hours) on September 24, 2013, and the TODAY function calculated to 41541.  That means that it is technically storing 12:00am on September 24, 2013.

NOW()

A similar function called NOW always returns the current date and time’s serial number. The NOW function is just entered as:

=NOW()

Again,  at 6:30pm (18:30 hours) on September 24, 2013, the function calculated to 41541.77081333… NOW stores the exact time and date, down to the second.

EDATE() and EOMONTH()

The EDATE function gives the date the specified number of months away from the input date. The EOMONTH function gives the date of the last day of the month. It can do so for the current month or a number of months in the future or the past. The syntax for each is as follows:

=EDATE(start_date, months)
=EOMONTH(start_date, months)

The start_date can be any date-formatted cell reference or date serial number.

The months field can be any number, though only the integer value will be used (e.g. it treats 2.8 as 2).

The EDATE and EOMONTH functions strip the time value from the date. For example, For example, if cell A1 stores September 10, 2013, we can get the value 2 months ahead as follows:

=EDATE(A1,2)

Returns 12:00am (0:00 hours) on November 10, 2013, or 41588. This function works even though the months have different numbers of days (September and November have 30, October has 31).

=EOMONTH(A1,2)

Returns 12:00am (0:00 hours) on November 30, 2013, or 41588. Again, this function works even though the months have different numbers of days.

WORKDAY()

Occasionally, it may be useful to count ahead based on work-days (Monday-Friday) instead of all 7 days of the week… For that, Excel has provided WORKDAY. The syntax for WORKDAY is as follows:

=WORKDAY(start_date, days, [holidays])

The start_date is as above.

The days input is the number of workdays ahead (or behind) of the present day you would like to move.

The [holidays] input is optional, but lets you disqualify specific days (like Thanksgiving or Christmas, for example), which might otherwise fall during the work week. These are date serial numbers provided in an array bounded by brackets: { }. To specify multiple holidays, the dates must be held in cells – it is not possible to put multiple DATE functions in an array.

For example, let’s find the date 6 work days before 6:00pm (18:00 hours) on September 10, 2013 (stored in cell A1). Monday, September 2nd is Labor Day, so let’s include that as a holiday:

=WORKDAY(A1,-6,DATE(2013,9,2))

Returns 12:00am (0:00 hours) on August 30, 2013, or 41516. (Note that the function strips the time portion of the date.)

WORKDAY.INTL() (Excel 2010 and newer)

For newer versions of Excel (2010 and later), there is another version of WORKDAY called WORKDAY.INTL. WORKDAY.INTL works just like WORKDAY, but it adds the ability to customize the definition of the “weekend”. The syntax for WORKDAY.INTL is as follows:

=WORKDAY.INTL(start_date, days, [weekend], [holidays])

The start_date, days, and [holidays] inputs work just like the normal WORKDAY function.

The [weekend] input has the following options:

WorkDay.Intl Weekend

Retrieving Dates in Excel

DAY(), MONTH(), and YEAR()

Now we know how define dates, but we still need to be able to work with them. Serial numbers don’t make it easy to extract months, years, and days, nevermind hours, minutes, and seconds. That’s why Excel has specific functions for pulling out each of these values. For working with the calendar, there is DAY, MONTH, and YEAR. The syntax is simple:

=DAY(serial_number)
=MONTH(serial_number)
=YEAR(serial_number)

The serial_number in each can be any date-formatted cell reference. For example, if cell A1 stores September 10, 2013, we can use each of the formulas in turn:

=DAY(A1)

Returns 10 as a numeric value.

=MONTH(A1)

Returns as a numeric value.

=YEAR(A1)

Returns 2013 as a numeric value.

We could have also given the direct serial number for September 10, 2013:

=DAY(41527)

Returns 10 as a numeric value.

Retrieving Times in Excel

HOUR(), MINUTE(), and SECOND()

For times, the process is very similar. Excel has function to retrieve the hours, minutes, and seconds from a time stamp, conveniently named HOUR, MINUTE, and SECOND. The syntax is identical:

=HOUR(serial_number)
=MINUTE(serial_number)
=SECOND(serial_number)

The serial_number in each can be any time/date-formatted cell reference. For example, if A1 stores 6:15:30pm (18:15 hours, 30 seconds) on September 10, 2013, we can use each of the formulas in turn:

=HOUR(A1)

Returns 18 as a numeric value.

=MINUTE(A1)

Returns 15 as a numeric value.

=SECOND(A1)

Returns 30 as a numeric value.

We could have also given the direct serial number for  6:15:30pm (18:15 hours, 30 seconds) on September 10, 2013:

=SECOND(41527.7607638889)

Returns 30 as a numeric value.

Additional Date Retrieving Functions

WEEKDAY() and WEEKNUM()

Dates don’t just have month and year information. They also encode indirect information… September 10, 2013 happens to also be a Tuesday. Excel has a few of functions to work with the week aspect of dates: WEEKDAY and WEEKNUM. The syntax is as follows:

=WEEKDAY(serial_number, [return_type])
=WEEKNUM(serial_number, [return_type])

The serial_number in each can be any date-formatted cell reference. Since [return_type] is optional, each function assumes that each week starts on Sunday. If cell A1 stores September 10, 2013 (a Tuesday), we can use each of the formulas in turn:

=WEEKDAY(A1)

Returns 3, since Tuesday is the 3rd day of a week that starts on Sunday.

=WEEKNUM(A1)

Returns 37, since September 10, 2013 is in the 37th week of 2013, when you start counting weeks from Sunday.

The [return_type] allows you to specify a different default week arrangement. You could let the week start on Monday and run until Sunday, or Saturday until Friday, for example. Excel is annoying, however, and makes the entry different for WEEKDAY and WEEKNUM. The full list of options for WEEKDAY is as follows:

Week Return Type

Options 2 and 11 are functionally the same – the first is just there for backwards compatibility with earlier versions of Excel.

The full list of options for WEEKNUM is as follows:

WeekNum Return Type

Counting and Tracking Dates

Dates can be added and subtracted like normal numbers because they’re stored as serial numbers. That lets you count the days between two different dates. Sometimes, though, you need to count by a different metric.

NETWORKDAYS()

Above, we learned about WORKDAY, which lets you move back and forth a set number of workdays, ignoring weekends and holidays. But what if you need to measure the number of workdays between two dates? For that, Excel provides NETWORKDAYS. The formula syntax is as follows:

=NETWORKDAYS(start_date, end_date, [holidays])

The start_date and end_date can be any date-formatted cell reference.

The [holidays] input is optional, but lets you disqualify specific days (like Thanksgiving or Christmas, for example), which might otherwise fall during the work week. These are date serial numbers provided in an array bounded by brackets: { }. To specify multiple holidays, the dates must be held in cells – it is not possible to put multiple DATE functions in an array.

For example, if A1 contains 6:00pm (18:00 hours) on September 10, 2013 and B1 contains 9:00am (9:00 hours) on December 2, 2013, we can use NETWORKDAYS to find the number of workdays between the two dates.

Let’s exclude Columbus Day (October 14, 2013), Veterans Day (November 11, 2013), and Thanksgiving Day (November 28, 2013) as holidays. To do so, we have to store those dates in other cells. Let’s put them in C1, C2, and C3:

=DATE(2013,10,14)
=DATE(2013,11,11)
=DATE(2013,11,28)

Now, we can combine them in the function:

=NETWORKDAYS(A1,B1,C1:C3)

The function returns 57 as a numeric value.

NETWORKDAYS.INTL() (Excel 2010 and newer)

For newer versions of Excel (2010 and later), there is another version of NETWORKDAYS called NETWORKDAYS.INTLNETWORKDAYS.INTL works just like NETWORKDAYS, but it adds the ability to customize the definition of the “weekend”. The syntax for NETWORKDAYS.INTL is as follows:

=NETWORKDAYS.INTL(start_date, end_date, [weekend], [holidays])

The start_dateend_date, and [holidays] inputs work just like the normal WORKDAY function.

The [weekend] input has the following options:

NETWORKDAYS.Intl Weekend

YEARFRAC()

Sometimes it’s useful to measure how much time has passed in years, but subtracting the YEAR function will only round down to the nearest full year. YEARFRAC takes two dates and provides the portion of the year between them. The syntax is as follows:

=YEARFRAC(start_date, end_date, [basis])

The start_date and end_date can be any date-formatted cell reference.

The [basis] input is optional, but lets you specify the “rules” for measuring the difference. Most of the time, you’ll want to use option 1, but here is the full list:

YearFrac BasisFor example, if A1 contains September 10, 2013 and B1 contains December 2, 2013, we can use YEARFRAC to find the decimal portion of a year between the two dates:

=YEARFRAC(A1,B1,1)

Returns 0.227397260273973.

DATEDIF() (Undocumented Function)

The YEARFRAC function gives you the difference between dates as a fraction of a year, but sometimes you need more control. There is a powerful hidden function in Excel called DATEDIF that can do much more. It can tell you the number of years, months, or days between two dates. It can also track based on only partial inputs, ignoring years or months when calculating days. The syntax for DATEDIF is as follows:

=DATEDIF(start_date, end_date, unit)

The start_date and end_date can be any date-formatted cell reference.

The unit input asks you to specify a string that represents the type of output you want. This is slightly cumbersome, since you must wrap the input in quotes (” “).

For example, if A1 contains September 10, 2012 and B1 contains December 2, 2013, we can use DATEDIF to find the number of full years between the two dates:

=DATEDIF(A1,B1,"Y")

Returns 1 as a numeric value.

Using the same start_date and end_date inputs, here are the output possibilities for DATEDIF using different unit parameters:

DateDif Unit

Every time, the unit must be put in quotes (e.g. “Y” or “MD”).

Converting Dates and Times from Text

DATEVALUE() and TIMEVALUE()

All of the above functions work perfectly with date-formatted serial numbers in Excel. Unfortunately, dates and times are often imported into worksheets as text. Most of the assorted functions like MONTH and HOUR are reasonably intelligent about converting on the fly. Occasionally it’s useful to build a date value through concatenation. The two functions Excel provides for this purpose are DATEVALUE and TIMEVALUE. The syntax for each is as follows:

=DATEVALUE(date_text)
=TIMEVALUE(time_text)

The date_text and time_text accept any text string that looks like a date or time.

This is how DATEVALUE responds to various date_text inputs:

DateValue Text Examples

This is how TIMEVALUE responds to various time_text inputs:

TimeValue Text Examples

Converting Dates and Times to Text

TEXT()

Getting data converted to dates and times is great, but you may also need to get it back out. Sometimes, you need a special format. Other times, you need to look for a date in a text string, and have to match using string tools like FIND and SEARCH. There is one master function for converting dates and times to text strings in Excel, called TEXT. The syntax for TEXT is as follows:

=TEXT(value, format_text)

The value can be any date or time-formatted cell reference.

The format_text input has a large number of options, summarized here:

Text Format_Text Inputs

The outputs can be combined with simple formatting characters to produce standard date formats. Using the date 5:07:03am (05:07 hours, 3 seconds) on September 10, 2013, here are examples of possible outputs:

Text Output Examples

A Common Problem

One issue people frequently run into is that Excel occasionally misinterprets text fields as dates. An example is here:

Common Error

Be careful when entering dates, especially if you are importing from other data sources, to make sure that your “Jan-13” is being stored as January 1, 2013 and not January 13, 2013!

Get the latest Excel tips and tricks by joining the newsletter!

Andrew Roberts ThumbnailAndrew Roberts has been solving business problems with Microsoft Excel for over a decade. Excel Tactics is dedicated to helping you master it.

Join the newsletter to stay on top of the latest articles. Sign up and you’ll get a free guide with 10 time-saving keyboard shortcuts!

Other posts in this series…

Понравилась статья? Поделить с друзьями:
  • Data text to column excel
  • Data text file to excel
  • Data template in excel
  • Data tabs in excel
  • Data table in word table