Skip to content
Start free

Is 03/04/2026 March 4 or April 3?

Find out why programs guess the order of a date, why the most dangerous error is the one that doesn't warn you, and learn to tell them the format.

Free course. Your Maestro, an AI, .

The branch sends its September and October sales with the date written the way it's done in Mexico and most of the world: day, month and year. If you're used to the US order, month first, this is exactly the file that will bite you.

ventas.csv
fecha,sucursal,importe
02/09/2026,Centro,1520.00
05/09/2026,Centro,890.50
03/10/2026,Zapopan,2210.00
07/10/2026,Centro,640.00
11/10/2026,Zapopan,1335.25
Synthetic data, CC0. The file, seen as text.

Your boss asks for sales by month. You run the calculation in pandas and the result says there were sales in February, March, May, July and November. Nobody sold anything in February: the file covers September and October.

The file isn't wrong. 02/09/2026 is, to whoever wrote it, September 2. But in a CSV a date is text, just like everything else, and text doesn't say which order the day and month go in. The program reading it has to assume. And if it assumes the month goes first, as most US readers would, 02/09/2026 is February 9.

When a value has a day greater than 12, like 13/09/2026, there's no doubt: there is no month 13. But if every day in your file is from 1 to 12, both readings are valid dates, and the program picks one without telling you. That's the worst case in the whole course: an error that doesn't look like an error.

Predict what each reader does with the branch's file:

pandas guesses

Example 1 of 4

example.py
import pandas as pd

with open("ventas.csv", "w", encoding="utf-8") as archivo:
    archivo.write("fecha,sucursal,importe\n02/09/2026,Centro,1520.00\n05/09/2026,Centro,890.50\n03/10/2026,Zapopan,2210.00\n07/10/2026,Centro,640.00\n11/10/2026,Zapopan,1335.25\n")

ventas = pd.read_csv("ventas.csv")
ventas["fecha"] = pd.to_datetime(ventas["fecha"])
print(ventas["fecha"].dt.month.tolist())

A guess is fine: it's kept as you wrote it, so you can compare. Only you and your Maestro see your predictions.

Example 2 of 4, opens once you explain this one

Make your prediction

The lesson isn't "pandas reads wrong and DuckDB reads right." It's that both guess, and the guess can come out differently depending on the program, the version or the values the file holds that month. If one month all the sales fall between the 1st and the 12th, the same script that used to work starts giving wrong months.

The way out is to state the format every time you read dates from a CSV:

WhereHow to say day/month/year
pandas, when convertingpd.to_datetime(column, format="%d/%m/%Y")
pandas, when readingpd.read_csv(..., parse_dates=["fecha"], date_format="%d/%m/%Y")
DuckDBread_csv(..., dateformat='%d/%m/%Y')

The codes %d, %m and %Y are the same in both programs. pandas also accepts dayfirst=True, which gave the right result in our run, but format is more precise: if a date doesn't match it, pandas stops with an error instead of guessing.

And when you're the one writing the file, there's a form that leaves no room for doubt: year-month-day with hyphens, 2026-09-02. In the sandbox, pandas and DuckDB read it as a date with no options and with the right month. And when pandas writes dates to a CSV, that's the way it writes them by default.

Ask your Maestro how to tell the date order of a file somebody sent you.

In Excel

Excel also interprets dates when it opens a CSV. Microsoft puts it this way: when Excel opens a .csv file, it "uses the current default data format settings to interpret how to import each column of data", and it gives exactly this example: "the format of a data column in the .csv file may be MDY, but Excel's default data format is YMD". Its advice is to bring the file in with the Import Text Wizard or with From Text/CSV, where you control how each column is converted, instead of opening it with a double click. You'll do that in module 4.

The same Automatic Data Conversion page you saw for zeros has an option for dates, Convert "date-like" combinations of continuous letters and numbers into a date, for cases like JAN1, which Excel turns into January 1. Microsoft says that with it off, "JAN1 remains as JAN1 in text, and isn't converted to the date January 1," and it warns that values that include a space or other characters, such as JAN 1 or JAN-1, may still be treated as dates.

Warning: Check the months, not just that there's no error

After reading dates, print which months or what date range came out, with something like ventas["fecha"].dt.month.value_counts(). If the file is from September and February shows up, the problem is in the reading.

Try it

This program adds up the branch's sales by month. Run it and read the months that come out. Then tell pandas the correct format.

Run the program: it shows sales in months 2, 3, 5, 7 and 11. Change the date conversion so pandas reads day/month/year. You're done when only September (9) with 2410.50 and October (10) with 4185.25 show up.

Run the program: it shows sales in months 2, 3, 5, 7 and 11. Change the date conversion so pandas reads day/month/year. You're done when only September (9) with 2410.50 and October (10) with 4185.25 show up.

Run your code to see what it prints and the value of its last expression. Every run starts fresh.

Ready to run your code.

Run your code to see its output here.

Run it yourself

Check yourself: A vendor sends you a file and the first date is 03/04/2026. What date is it?