Who this lesson is for
Almost every workbook that a macro touches has a date in it somewhere: an invoice date, a delivery date, a log of when a report was produced, a deadline that turns red. Dates are also where VBA code breaks most quietly. A macro that works on your PC gives different answers on a colleague's machine in another country, a column of dates refuses to sort, or a report run just before midnight stamps two different days on the same row. This lesson is for anyone who writes or maintains Excel macros and wants dates to behave as reliably as numbers do.
The free lab above contains the macro StampRunLog. Each time you run it, it appends a row to a Run Log sheet: the day, the clock time, the full timestamp, the weekday, the number of days since a project start on 1 January 2026, and how many seconds the macro took. Below we use that log to explain what Date, Time and Now really return, what lands in each cell, and the habits that keep dates sortable, comparable and correct wherever the workbook is opened.
The core idea: a date is a number with a costume
VBA has three functions that read the system clock. Date returns today with no time part, Time returns the current time with no date part, and Now returns both together. All three return a value of the Date data type, and underneath, a Date is a number: the whole part counts days from a fixed starting point, and the fraction is the share of the day that has passed. Noon is 0.5, 06:00 is 0.25, and 14:07:32 is about 0.5886.
This is why date arithmetic in VBA is so pleasant once your values are real dates. d + 30 is thirty days later, endDate - startDate is the number of days between two dates, and < and > compare them correctly. For dates from March 1900 onwards the number is the same serial number Excel uses in cells, so a VBA Date written into a cell becomes an ordinary Excel date that formulas such as =A2+30 or =NETWORKDAYS(A2,B2) understand. Lesson 2 of this course looks at the counting start and the rare cases where VBA and the worksheet disagree.
The printed form, such as 9/13/2026 or 13.09.2026, is only a costume. Debug.Print and message boxes dress the number in the short-date format of the Windows regional settings, and a cell dresses it in its number format. The value is the same everywhere; only the presentation changes. Keep that separation in mind and most date problems never happen.
Worked example: three entries in the Run Log
Suppose, for example, that you run the lab macro twice on Sunday 13 September 2026 in the afternoon and once more on Monday morning. The table shows what each column holds, the number hiding under each value, and a worksheet formula that would produce the same result from the full timestamp in column C. The seconds in column F depend on your computer, so they are illustrative.
| Column | Written by the macro | Run 1 | Run 2 | Run 3 | Worksheet equivalent (row 2) |
|---|---|---|---|---|---|
| A Day | DateValue(stampedAt) | 2026-09-13 (46278) | 2026-09-13 (46278) | 2026-09-14 (46279) | =INT(C2) |
| B Clock | TimeValue(stampedAt) | 14:07:32 (0.5886) | 14:09:05 (0.5896) | 08:30:10 (0.3543) | =MOD(C2,1) |
| C Full stamp | stampedAt (one read of Now) | 46278.5886 | 46278.5896 | 46279.3543 | =NOW() (but it keeps changing) |
| D Weekday | Format(stampedAt, "dddd") | Sunday | Sunday | Monday | =TEXT(C2,"dddd") |
| E Days into project | DateValue(stampedAt) - projectStart | 255 | 255 | 256 | =INT(C2)-DATE(2026,1,1) |
| F Seconds | Round(Timer - startedAt, 3) | for example 0.016 | 0.008 | 0.012 | none |
A few things stand out. Columns A, B and C are real Date values, so you can sort the log, filter it by month with the date filter tree, or sum the hours between two stamps. Column D is deliberately text: a weekday name is a label for people, and it is written in the display language of Windows, so an English PC writes Sunday and a German one Sonntag. Column E is a plain count of days, which is why the lab stores it in a Long. Had it been declared As Date, the cell would show 255 days after the counting start, a meaningless date in September 1900.
Notice also that =NOW() is not a substitute for the macro. Worksheet NOW and TODAY are volatile: they recalculate every time the workbook does, so a log built with them would show the current time on every row. A macro writes a value once and it stays. In the worksheet you can do the same by hand with Ctrl+; for today's date and Ctrl+Shift+; for the current time, both entered as fixed values.
Read the clock once
The most important line in the lab is one of the shortest: stampedAt = Now. Every mention of Now asks Windows for the time again. If a macro wrote Now into three cells on three lines, the values would differ by fractions of a second, and if it ran at 23:59:59 the last cell could fall on the next day. Reading the clock once into a variable and using that variable everywhere guarantees that every column of a row describes the same moment.
Dim stampedAt As DatestampedAt = Nowws.Cells(nextRow, 1).Value = DateValue(stampedAt) ' day onlyws.Cells(nextRow, 2).Value = TimeValue(stampedAt) ' clock onlyws.Cells(nextRow, 3).Value = stampedAt ' both
The same rule applies to Date in longer macros. A report that runs across midnight and calls Date at the start and again at the end can label its header with one day and its footer with the next. Capture runDate = Date at the top and pass that variable around.
Timer is a different tool. It returns the seconds since midnight as a number with a fractional part, which makes it a handy stopwatch: store it at the start, subtract at the end, and you know how long the code took. It is not a clock, because it falls back to zero at midnight; a measurement that crosses midnight comes out negative. For timing a macro that is rarely a problem, but never use Timer to record when something happened.
Whose clock is it?
Now, Date and Time read the clock of the computer that runs the macro, in its local time zone, and the value carries no time zone with it. For a log kept on one PC that is exactly what you want. It becomes a question as soon as a workbook is shared: a colleague in another office who runs the same macro stamps his local time, and nothing in the cell says so. Daylight saving time adds a second wrinkle. On the night the clocks go back, one hour of local time happens twice, so two stamps can look identical although they are an hour apart, and on the night they go forward one hour of local time never happens at all.
For most business logs this is harmless, but it is worth deciding consciously. If people in several time zones write to the same sheet, add a column with the user name (Application.UserName) and, if needed, a note of the office or time zone, so that nobody later reads a nine-hour gap as a slow process. And if the system clock of a PC is wrong, every stamp it writes is wrong too: VBA has no independent source of time, it simply trusts Windows.
How to run the lab macro and make it your own, step by step
- Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) with File โ Save As.
- Press
Alt+F11, choose Insert โ Module, and paste the fullStampRunLogcode from the lab. - Click inside the procedure and press
F5two or three times, a few seconds apart. Switch back to Excel withAlt+F11or the taskbar: the Run Log sheet has one row per run. - Click a cell in column A and look at the formula bar, then press
Ctrl+Shift+~to apply the General format temporarily (or change it via Home โ Number Format โ General) and see the serial number underneath. Undo withCtrl+Z. - In the editor, open the Immediate window with
Ctrl+Gand type?CDbl(Now). You get today's serial number with its fraction, the same idea as in the diagram above. - Type
?TypeName(Worksheets("Run Log").Range("A2").Value). The answerDateconfirms that the cell holds a real date. Try the same on column D and you getString. - Change
projectStart = DateSerial(2026, 1, 1)to the start date of a real project of yours, and column E counts the days since then on every run. - To log something useful, call
StampRunLogas the last line of another macro, for example a monthly import, so every run of that macro leaves a timestamped trace.
Store dates, format for people
The lab closes with the trap that costs the most time: writing a nicely formatted date into a cell. Format(Now, "dd mmm yyyy") returns a String. Put that into a cell and it looks like a date, but Excel stores text, and text behaves differently in every way that matters. The diagram shows the first symptom you are likely to see, a sort that makes no sense.
The other symptoms are just as annoying: the AutoFilter shows a flat list of strings instead of grouping by year and month, SUMIFS with a date criterion returns zero, and the next macro that subtracts two of these cells stops with a type mismatch. The fix is to keep value and presentation separate:
ws.Range("A1").Value = Nowws.Range("A1").NumberFormat = "dd mmm yyyy"
Use Format where a human reads the result and nothing calculates with it afterwards: a message box, a sheet name, a file name such as "Report_" & Format(Date, "yyyy-mm-dd") & ".xlsx". The year-month-day pattern in file names has a bonus: those names sort in date order in File Explorer.

Common mistakes and how to spot them
- Dates declared as String.
Dim d As Stringloses comparison and arithmetic. DeclareAs Date. If you suspect a cell holds text,?TypeName(cell.Value)in the Immediate window settles it, and the worksheet=ISNUMBER(A2)returns FALSE for a text date. - Calling Now several times for one record. Values drift apart and can straddle midnight. Read the clock once into a variable.
- Date literals typed the local way. A literal such as
#3/4/2026#is always read as month/day/year, so it is 4 March, never 3 April, whatever your regional settings. UseDateSerial(2026, 4, 3)and there is nothing to misread. - A day count stored in a Date variable. The cell then shows a date in 1900 instead of a number. Use
Longfor whole days andDoublefor fractions of days. - Naming a variable Date, Time or Now. It hides the built-in function inside that procedure and produces confusing results. Pick names like
runDateorstampedAt. - Using Timer as a clock. It resets at midnight. Use it only to measure durations.
- Cell formats and Format patterns mixed up. The two use similar letters but are separate systems; lesson 5 lists the codes that differ, including the minutes.
Quick reference
| VBA | Worksheet | What it gives you |
|---|---|---|
Date | =TODAY() | Today, no time part |
Time | =MOD(NOW(),1) | Current time, no date part |
Now | =NOW() | Date and time together |
DateValue(d) / TimeValue(d) | =INT(C2) / =MOD(C2,1) | Day part / time part of a timestamp |
DateSerial(2026, 1, 1) | =DATE(2026,1,1) | A date built from year, month and day |
Format(d, "dddd") | =TEXT(C2,"dddd") | Weekday name as text |
Timer | none | Seconds since midnight, for timing code |
TypeName(cell.Value) | =ISNUMBER(A2) | Tells a real date from text |
Range.NumberFormat = "yyyy-mm-dd" | Ctrl+1 โ Number โ Custom | Changes the display only |
Ctrl+; ยท Ctrl+Shift+; | Type today's date / current time as fixed values |
Real-world uses
- Audit trail for recurring macros. Call a logging routine at the end of every import or month-end macro so you can answer "when was this last updated, and by which run?" without guessing.
- Stamping edits. In a shared tracker, a
Worksheet_Changeevent can writeNowinto a "last changed" column next to the edited row, as a value that does not recalculate. - Ageing reports. Days between an invoice date and
Dateare a simple subtraction once both are real dates, which is the basis for 0โ30, 31โ60 and 61โ90 day buckets in accounts receivable. - Time-stamped file names. Saving exports as
"Sales_" & Format(Now, "yyyy-mm-dd_hhnn") & ".csv"gives each run a unique name that sorts chronologically. - Measuring macro speed. The
Timerpattern from the lab shows whether a change to your code really made it faster, in milliseconds rather than gut feeling.
What you will build in the rest of this course
This first lesson is free. The six lessons below make up the rest of the course, available as a one-time purchase of $9.90, and each one comes with code you can run straight away.
Dates Are Really Numbers. The Double under every Date, stripping the time off a timestamp, where the counting starts, and the difference between Value and Value2 when you read dates from cells.
Building Dates with DateSerial. Three numbers in, one date out, and why it happily accepts impossible values like month 13 or day 0. That behaviour gives you the classic month-end trick and safe rebuilding of dates from parts.
DateAdd and DateDiff. Shifting a date by months, quarters or weeks, why adding a month is cleverer than adding thirty days, and measuring gaps in the unit you actually need.
Formatting Dates for People. The Format codes worth memorising, why minutes are nn in VBA, and a firm rule for when text is the right output and when it is not.
Parsing Dates That Arrived as Text. CSV files, web exports and other people's systems deliver dates as strings. You will see when CDate can be trusted, when it guesses wrongly, and how to take the text apart yourself so day and month never swap.
Month Ends and Working Days. Month, quarter and year boundaries without special cases, weekday logic, and borrowing Excel's WORKDAY and NETWORKDAYS from VBA for due dates and service-level calculations.
Summary
Date, Time and Now read the clock, and all three return a Date: a number whose whole part counts days and whose fraction is the time of day. Declare dates As Date, read Now once per record, keep day counts in a Long, build fixed dates with DateSerial rather than literals, and write real dates into cells with a NumberFormat instead of formatted text. Now scroll back up to the lab, run StampRunLog a few times, and check with TypeName that columns A to C hold dates and column D holds text.
Frequently asked questions
What is the difference between Date, Time and Now in VBA?
Date returns today without a time, Time returns the current time without a date, and Now returns both. All three return the Date data type, so they can be compared and used in arithmetic.
How do I insert a timestamp with VBA that does not change?
Assign Now to the cell value, for example Range("A2").Value = Now, and set a NumberFormat such as "yyyy-mm-dd hh:mm:ss". Unlike the worksheet NOW() function, a value written by a macro does not recalculate.
How are dates stored in Excel VBA?
As a number: the whole part counts days and the fraction is the time of day, so noon is 0.5. For dates from March 1900 onwards this matches the serial numbers Excel uses in cells.
Why does my date column sort in the wrong order?
The cells most likely hold text, often because a macro wrote Format(...) into them. Text sorts character by character, so write the Date value itself and set the cell NumberFormat for display.
How do I get only the date part of Now in VBA?
Use Date if you want today, or DateValue(stampedAt) to strip the time from a timestamp you already have. Int(stampedAt) also works for dates after 1899 because it removes the fraction.
Is #3/4/2026# the 3rd of April or the 4th of March in VBA?
It is always 4 March 2026, because VBA date literals are read as month/day/year regardless of regional settings. DateSerial(2026, 4, 3) avoids the ambiguity completely.
Keep going: Dates & Times
This free lab is lesson 1 of 7. Unlock the other 6 hands-on labs, the final exam and your certificate for a one-time โฌ9.90.
- Dates Are Really Numbers
- Building Dates with DateSerial
- DateAdd and DateDiff
- Formatting Dates for People
- Parsing Dates That Arrived as Text
- Month Ends and Working Days