The fastest way to find how many days passed between two dates
In Excel, subtract the earlier date from the later date. If your earlier date is in cell A1 and your later date is in cell B1, type =B1-A1 into an empty cell and press Enter. Excel will show you the number of days between them. This works because Excel stores dates as numbers — January 1, 1900 is 1, January 2, 1900 is 2, and so on.
This matters for security work because you often need to know how long a device went without updates, or how many days passed between when a vulnerability was announced and when your system was patched. A straightforward subtraction tells you whether that gap was days, weeks, or months.
If your result shows a decimal (like 5.5), that means 5 full days plus 12 hours. If you want only whole days, wrap your formula in the INT function: =INT(B1-A1). This rounds down to the nearest whole number.
Key Takeaways
- Subtract the earlier date from the later date using a straightforward formula like =B1-A1 to get the number of days between them.
- Excel stores dates as numbers, so subtraction works directly without any special date functions needed.
- Use =INT(B1-A1) if you want whole days only and need to remove decimal hours.
- The DATEDIF function calculates differences in days, months, or years and works well when you need a specific unit of time.
- For security logs, always check that your dates are formatted as actual dates in Excel, not text, or the subtraction will fail.
When you need the answer in months or years instead of days
Use the DATEDIF function when you want the result in months or years. The formula is =DATEDIF(A1,B1,"D") for days, =DATEDIF(A1,B1,"M") for months, or =DATEDIF(A1,B1,"Y") for years.
DATEDIF is useful for tracking how long a device has been in service or how many months have passed since a major security update. For example, if you want to know how many complete months your system has gone without a patch, DATEDIF with the "M" unit gives you that directly.
The order matters: the earlier date goes first, the later date goes second. If you reverse them, you get a negative number or an error. DATEDIF also ignores the time portion of a date — it only looks at the day, month, and year.
Making sure Excel reads your dates correctly
If your formula returns an error or a very large number, Excel is probably reading your dates as text instead of actual dates. Text that looks like a date (such as "1/15/2024") will not subtract correctly.
To check, click on the cell with the date and look at the formula bar at the top. If you see an apostrophe before the date (like '1/15/2024), it is stored as text. To fix this, delete the content, type the date again, and press Enter. Alternatively, select the column, go to the Data menu, choose Text to Columns, and click Finish — this converts text dates to real dates in one step.
Another way to force Excel to read something as a date is to use the DATEVALUE function: =DATEVALUE(A1). This converts text that looks like a date into an actual date that you can use in calculations.
Calculating time differences when hours and minutes matter
If your log entries include times (like "1/15/2024 14:30:00"), the straightforward subtraction still works, but the result will include a decimal. The whole number is days; the decimal represents the fraction of a day. To convert that decimal to hours, multiply by 24.
For example, if your result is 2.5, that means 2 full days plus 0.5 of a day. Multiply 0.5 by 24 to get 12 hours. So the total is 2 days and 12 hours.
If you want hours and minutes displayed clearly, use a formula like =INT(B1-A1)&" days "&INT(MOD(B1-A1,1)*24)&" hours". This breaks the result into whole days and whole hours in a readable format. The MOD function extracts just the decimal part, and multiplying by 24 converts it to hours.
Building a security log tracker with date calculations
Create a straightforward spreadsheet with three columns: Device Name, Last Update Date, and Days Since Update. In the Days Since Update column, use =TODAY()-B2 (assuming your date is in column B, row 2). The TODAY() function returns today's date, so this formula automatically calculates how many days have passed since the last update.
This updates every time you open the file, so you always see current numbers without manual recalculation. If a device shows more than 30 days since its last update, you know it needs attention soon.
You can also add conditional formatting to highlight cells where the number of days exceeds a threshold. Select the Days Since Update column, go to Conditional Formatting, choose Highlight Cell Rules, and set it to highlight any cell greater than 30 (or whatever your security policy requires). Devices that are falling behind will stand out when ready.
Common mistakes that break date calculations
Mixing date formats is the most common problem. If one cell uses MM/DD/YYYY and another uses DD/MM/YYYY, Excel may misread one of them. Always use the same format throughout a column. The safest approach is to use YYYY-MM-DD (like 2024-01-15), which is unambiguous in any region.
Another mistake is forgetting that Excel counts from January 1, 1900 as day 1. If you see a result like 44,927, that is not an error — it is the number of days since 1900. This happens when you accidentally format a number as a date instead of calculating a difference. Double-check that you are subtracting two dates, not doing something else.
Blank cells also cause problems. If either cell in your formula is empty, you get an error or a wrong result. Before you calculate, make sure both date cells contain actual dates. Use the IFERROR function to catch these: =IFERROR(B1-A1,"Check dates") will show "Check dates" instead of an error if something is wrong.
Frequently Asked Questions
What if my dates are from different years?
The subtraction still works exactly the same way. Excel counts every single day from the earliest date to the latest, regardless of whether they span months or years. If you subtract January 15, 2023 from January 15, 2024, you get 365 (or 366 in a leap year).
Can I calculate the difference between a date and right now?
Yes, use the TODAY() function or NOW() function. TODAY() gives you today's date at midnight; NOW() gives you the current date and time down to the second. For example, =TODAY()-A1 tells you how many days have passed since the date in A1 until today.
Why does my DATEDIF formula say it is not recognized?
DATEDIF is not available in all versions of Excel, particularly older versions or some regional builds. If you get a #NAME? error, use the straightforward subtraction method instead: =INT(B1-A1) for days, or =INT((B1-A1)/30.44) for approximate months (dividing by 30.44, the average days per month).
How do I show the result as "X days ago" instead of just a number?
Use the ampersand (&) to join text and numbers: =INT(TODAY()-A1)&" days ago". This displays something like "23 days ago" instead of just 23. You can customize the text to say anything you want.