2 / 6 · Intro
Numbers, text and dates
Type 007 into a cell and both Excel and Google Sheets store the number 7. The two zeros are gone unless you start with an apostrophe.
Jump to the 10 practice questionsYou will learn
- Tell numbers, text, logical values and dates apart
- Read a date as a serial number
Before this: Cells, rows, columns and ranges
1Explain
What a cell can hold
When you type into a cell and press Enter, the spreadsheet decides what kind of value you typed. There are four kinds you meet every day. A number is something it can calculate with, such as 42, 3.5 or 12%. Text is everything else, such as a name or a product code. A logical value is TRUE or FALSE. An error value, such as #DIV/0!, is what a formula produces when it cannot give an answer. A cell can also be empty, which is different from a cell that holds 0.
2Explain
Left or right in the cell
You can usually tell the kind by looking. With the standard settings, numbers line up against the right edge of the cell and text lines up on the left. A column of prices with one value stuck on the left is therefore a warning sign. That value was stored as text and will be skipped by SUM. In the lab below, the panel names the kind of every cell you select, which saves guessing.
3Problem
A value on the left
With standard settings, a value sits against the left edge of its cell. What is it most likely to be?
Hint
Standard settings: numbers right, text left.
Solution
Answer: Text
Numbers, dates and percentages are all numbers and line up on the right; text lines up on the left.
4Explain
Leading zeros and the apostrophe
Some things look like numbers but are really labels: ZIP codes such as 02134, employee numbers such as 007, phone numbers that start with 0. Type them plainly and the spreadsheet turns them into numbers and drops the leading zeros. To keep them, type an apostrophe first: '02134. The apostrophe tells the program to store text, and it is not shown in the cell. Long identifiers are a second reason to use text. Microsoft gives Excel a number precision of 15 digits, so a 16-digit card number stored as a number loses its last digit.
5Problem
Typing 007
You type 007 into an empty cell. What number is stored?
Hint
The leading zeros are dropped.
Solution
Answer: 7
It is read as a number, and leading zeros are not part of a number.
6Problem
Keeping 02134
How do you keep a ZIP code such as 02134 exactly as typed?
Hint
One character in front.
Solution
Answer: Type '02134
The apostrophe stores the entry as text and is not displayed.
7Explain
Percentages and text that looks like numbers
Percentages work the other way. Typing 12% stores the number 0.12 and shows it as 12%, so =A5*100 gives 12. Text that looks like a number is not hopeless either: Microsoft's page on operators shows that ="1"+"2" gives 3, because the plus sign makes Excel convert text it can read as a number. Functions such as SUM are stricter and skip text in a range, which is why a column of numbers stored as text can quietly add up to 0.
8Problem
12% times 100
You type 12% into A5. What does =A5*100 return?
Hint
12% is stored as 0.12.
Solution
Answer: 12
12% is stored as 0.12, and 0.12 × 100 = 12.
9Problem
="1"+"2"
What does ="1"+"2" return in Excel?
Hint
The plus sign converts what it can.
Solution
Answer: 3
The plus sign makes Excel convert text it can read as numbers: 1 + 2 = 3.
10Explain
Dates are numbers in disguise
A date in a spreadsheet is stored as a serial number: a count of days. Microsoft's page on date systems gives the example that July 5, 2011 is stored as 40729 in Excel's 1900 date system, the default in current Excel for Windows and Mac. Older Mac versions used a 1904 system, where the same day is 39267, exactly 1,462 days less. Google's DATE help says Sheets counts the days since December 30, 1899, which gives the same 40729 for that day.
| You type | Stored as | Shown as |
|---|---|---|
| 007 | the number 7 | 7 |
| '007 | the text 007 | 007 |
| 12% | the number 0.12 | 12% |
| 2011-07-05 | the number 40729 | a date |
| TRUE | a logical value | TRUE |
| 3+4 | the text 3+4 (no = sign) | 3+4 |
11Explore
Dates as day counts
Counting days from 30 December 1899 gives the same serial numbers as Excel for any date after February 1900.
const day = new Date("2011-07-05T00:00:00Z");
const base = new Date("1899-12-30T00:00:00Z");
console.log((day - base) / 86400000);4072912Problem
5 July 2011
In Excel's 1900 date system, what serial number is July 5, 2011?
Hint
Pick it in the box above.
Solution
Answer: 40729
Microsoft's own example: 40729 (39267 in the 1904 system).
13Problem
The next day
So what serial number is July 6, 2011?
Hint
One more day, one more.
Solution
Answer: 40730
One day later is one more: 40729 + 1.
14Problem
1900 and 1904
How many days apart are Excel's 1900 and 1904 date systems?
Hint
Four years and a day.
Solution
Answer: 1462
40729 − 39267 = 1,462 days, four years and one day.
15Problem
Day zero in Google Sheets
From which day does Google Sheets count dates?
Hint
The same base the code uses.
Solution
Answer: 30 December 1899
Google's DATE help: the days since December 30, 1899.
16Problem
Digits of precision
How many digits of precision does Microsoft give for Excel numbers?
Hint
Microsoft gives fifteen.
Solution
Answer: 15
The specifications list "Number precision: 15 digits", so 16-digit IDs belong in text.
17Explore
Practice in the grid
Decide whether a column represents quantities or identifiers before entering a large list. Quantities can sensibly be added or compared by size; an identifier distinguishes one record from another. Adding employee identifiers does not produce a useful total, even if the entries contain only digits. Choosing text for identifiers protects their written form.
Drag to turn. Scroll or pinch to zoom.
18Practice
Days between two dates
serial(iso) is given. Finish daysBetween(a, b) so that it returns how many days b is after a, by subtracting serial numbers.
1
358
2function serial(iso) {
const day = new Date(iso + "T00:00:00Z");
const base = new Date("1899-12-30T00:00:00Z");
return (day - base) / 86400000;
}
function daysBetween(a, b) {
return 0;
}
console.log(daysBetween("2011-07-05", "2011-07-06"));
console.log(daysBetween("2026-01-01", "2026-12-25"));
console.log(daysBetween("2024-02-28", "2024-03-01"));
Hint
The later date has the bigger serial number.
A solution
function serial(iso) {
const day = new Date(iso + "T00:00:00Z");
const base = new Date("1899-12-30T00:00:00Z");
return (day - base) / 86400000;
}
function daysBetween(a, b) {
return serial(b) - serial(a);
}
console.log(daysBetween("2011-07-05", "2011-07-06"));
console.log(daysBetween("2026-01-01", "2026-12-25"));
console.log(daysBetween("2024-02-28", "2024-03-01"));19
Summary
- Four kinds of value: number, text, logical, error. Empty is not 0.
- Numbers sit right, text sits left by default.
- An apostrophe ('007) stores text and keeps leading zeros.
- Dates are day counts: July 5, 2011 is 40729 in both Excel (1900 system) and Google Sheets.