The request

From Jason King, Logistics Coordinator
Your goal
In F2:F35, return the number of whole days from the order date (column C) to the return date (column D) with DATEDIF. In G2:G35, return "outside" when that number is greater than the window in J1, otherwise "within".
- Fill
F2:G35with the right valuesnot done yet - With formulas, not typed numbersnot done yet
- Use
DATEDIFnot done yet
Your sheet
| A | B | C | D | E | F | G | H | I | J | K | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | order_id | category | order_date | returned_on | reason | days_to_return | window_check | Return window (days) | 30 | ||
| 2 | 5371 | Outdoor | 2024-05-24 07:19 | 2024-07-01 | changed_mind | ||||||
| 3 | 5480 | Outdoor | 2024-06-04 19:02 | 2024-07-01 | changed_mind | ||||||
| 4 | 5544 | Outdoor | 2024-06-12 13:10 | 2024-07-01 | changed_mind | ||||||
| 5 | 5560 | Kitchen | 2024-06-14 15:54 | 2024-07-02 | changed_mind | ||||||
| 6 | 5657 | Furniture | 2024-06-26 09:10 | 2024-07-03 | damaged | ||||||
| 7 | 5540 | Decor | 2024-06-11 21:57 | 2024-07-04 | changed_mind | ||||||
| 8 | 5521 | Kitchen | 2024-06-09 13:38 | 2024-07-05 | changed_mind | ||||||
| 9 | 5659 | Furniture | 2024-06-26 12:08 | 2024-07-05 | damaged | ||||||
| 10 | 5487 | Kitchen | 2024-06-05 13:43 | 2024-07-06 | late | ||||||
| 11 | 5682 | Textiles | 2024-06-27 22:03 | 2024-07-09 | wrong_item | ||||||
| 12 | 5505 | Decor | 2024-06-07 12:54 | 2024-07-10 | late | ||||||
| 13 | 5521 | Kitchen | 2024-06-09 13:38 | 2024-07-11 | late | ||||||
| 14 | 5720 | Decor | 2024-07-02 09:40 | 2024-07-11 | changed_mind | ||||||
| 15 | 5631 | Outdoor | 2024-06-22 18:31 | 2024-07-13 | late | ||||||
| 16 | 5720 | Textiles | 2024-07-02 09:40 | 2024-07-13 | changed_mind | ||||||
| 17 | 5768 | Textiles | 2024-07-09 01:46 | 2024-07-15 | changed_mind | ||||||
| 18 | 5773 | Lighting | 2024-07-09 20:08 | 2024-07-15 | damaged | ||||||
| 19 | 5505 | Textiles | 2024-06-07 12:54 | 2024-07-17 | changed_mind | ||||||
| 20 | 5584 | Kitchen | 2024-06-17 10:42 | 2024-07-17 | late | ||||||
| 21 | 5646 | Decor | 2024-06-24 20:42 | 2024-07-17 | changed_mind | ||||||
| 22 | 5798 | Lighting | 2024-07-12 20:19 | 2024-07-17 | damaged | ||||||
| 23 | 5777 | Decor | 2024-07-10 17:17 | 2024-07-18 | wrong_item | ||||||
| 24 | 5756 | Lighting | 2024-07-07 19:44 | 2024-07-19 | damaged | ||||||
| 25 | 5777 | Decor | 2024-07-10 17:17 | 2024-07-19 | wrong_item | ||||||
| 26 | 5798 | Outdoor | 2024-07-12 20:19 | 2024-07-19 | wrong_item | ||||||
| 27 | 5811 | Kitchen | 2024-07-14 18:39 | 2024-07-22 | wrong_item | ||||||
| 28 | 5867 | Kitchen | 2024-07-21 10:46 | 2024-07-26 | wrong_item | ||||||
| 29 | 5810 | Decor | 2024-07-14 17:41 | 2024-07-27 | changed_mind | ||||||
| 30 | 5798 | Outdoor | 2024-07-12 20:19 | 2024-07-28 | changed_mind | ||||||
| 31 | 5880 | Outdoor | 2024-07-22 10:49 | 2024-07-28 | wrong_item | ||||||
| 32 | 5901 | Kitchen | 2024-07-24 14:43 | 2024-07-29 | wrong_item | ||||||
| 33 | 5798 | Textiles | 2024-07-12 20:19 | 2024-07-30 | changed_mind | ||||||
| 34 | 5851 | Outdoor | 2024-07-18 17:47 | 2024-07-30 | damaged | ||||||
| 35 | 5905 | Textiles | 2024-07-24 20:48 | 2024-07-30 | changed_mind | ||||||
| 36 | |||||||||||
| 37 |
Loading the editor…
Reference solution
Mote checks your result
Press Check. Each right cell becomes a firefly in your lantern.
What Jason gets, and why
The lesson
Jason’s question is a classic operations metric: how long does a return take to come back, and which ones broke the policy? Because dates are numbers, the days between two dates is a subtraction. The catch is in the data: the order date has a time on it.
Subtracting dates
The order in row 2 was placed on 2024-05-24 at 07:19 (C2) and came back on 2024-07-01 (D2).
Try:
=D2-C2
The result is 37.70, not 38. A date without a time sits at midnight. The order came in at 7:19 in the morning, so between the two lie 37 full days plus the 0.70 of a day that was left of May 24. Format the cell with no decimals and it shows 38, which looks right, while every formula built on it still works on 37.70. Ordered on the 24th, back on the 1st: your colleagues count that as 38 days, so drop the time first.
One more surprise: Excel sometimes formats the result of a date subtraction as a date, and the
cell shows something like 1900-02-06. The number underneath is fine; set the cell’s format to
Number or General.
DATEDIF counts whole days
F2 =DATEDIF(C2,D2,"d")
DATEDIF(start, end, unit) takes the earlier date first and ignores the time of day. The unit
says what to count:
| Unit | Counts | C2 to D2 |
|---|---|---|
"d" |
whole days | 38 |
"m" |
whole months | 1 |
"y" |
whole years | 0 |
"m" and "y" are what you would use for tenure or a customer’s age in months. Two other ways
give the same 38 days: =D2-INT(C2) (INT cuts the time off the order date) and =DAYS(D2,C2)
(the end date comes first there). Excel doesn’t list DATEDIF in its formula autocomplete, an old
quirk, but it works in every version and in Google Sheets.
If the start is later than the end, DATEDIF returns #NUM!. On real data that is a useful
alarm: a return logged before its order is a data-entry error.
Outside the window or within it
The policy is “within 30 days”, and the window is in J1. A return on day 30 is within it; day
31 is not. So the test is >:
G2 =IF(F2>$J$1,"outside","within")
Fill both columns down to row 35. July has 34 returns in this sheet and 5 of them came back after the window. One sits exactly on the edge: row 20, a Kitchen return 30 days after its order, which is within. If you count 6 outside, check the operator.
Row 20 is also a reminder to read the columns: its reason is late, which means the delivery
arrived late, not that the return did. Name your own columns so nobody confuses the two.
Other date parts you’ll meet
Timestamps hold more than a date. =HOUR(C2) returns 7, the hour the order was placed, handy for
“when do people shop” questions. =WEEKDAY(D2,2) returns 1 for Monday through 7 for Sunday (July
1, 2024 was a Monday), and =NETWORKDAYS(C2,D2) counts only Monday to Friday, 27 here, for
policies stated in business days.
Common mistakes
- Plain subtraction on a timestamp. It gives fractional days. Use
DATEDIF, orINTon the timestamp. - The dates in the wrong order.
DATEDIF(D2,C2,"d")returns#NUM!;=C2-D2returns a negative number. >=instead of>. Day 30 is within a 30-day window;>=flags row 20 by mistake.- Typing 30 into the formula. Point at
$J$1, so a policy change is one cell.
Lantern lit!
Practised: datedifdate arithmetictimestampsif
- Solved
- No hints
- First run
