Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Determining the Day of the Month.

Determining the Day of the Month

by Allen Wyatt
(last updated May 24, 2014)

7

When creating macros in VBA, you may have a need to know the specific day of the month represented by a particular date. For instance, you may want to determine the day of the month on which the macro is being executed. The following code will do the trick:

iDay = Day(Date)

The Day function returns an integer value representing the day of the month of whatever date you provide. In this example, the Date function represents today's date, and so Day returns today's day of the month.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2502) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Determining the Day of the Month.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Summing Only Positive Values

If you have a series of values and you want to get a total of just the values that meet a specific criteria, then you need to ...

Discover More

Handling Negative Numbers in a Complex Custom Format

Custom formats are great for defining how a specific value in a cell should look. They aren't that great at doing complex ...

Discover More

Dealing with Text Length Limits and AutoFilter Drop-Down Lists

Excel has some built-in limits on what you can do with the program. When you run into those limits, it can be frustrating to ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (menu)

Converting UTC Times to Local Times

Dates and times are often standardized on UTC time, which is analogous to GMT times. How to convert such times to your local ...

Discover More

Inserting the Current Time with Seconds

If you need to insert the current time, with seconds, then you'll need the macro discussed in this tip. It's easy to use and ...

Discover More

Macro for Month Name

Need to know how to generate a full month name based on a date? It's easy to do, as discussed in this tip.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 2?

2014-05-30 09:39:04

Barry

@ Micky, Sorry I still disagree.

Just to wrap this up in case to ensure other readers aren't mislead.

Using Today() or Now() leaves the underlying value as a date serial number e,g, using Now()today (30th May2014) would give a value of 41789, this can be displayed as 30 by using the cell formatting but should you for whatever reason multiply this by, say, 2 you will get a totally different from using the Day(Now()) formula and performing the same calculation.


2014-05-29 15:40:39

Michael (Micky) Avidan

@Barry,
Disagreeing is good but not good enough.
The tip was refering to (quote): "returning an integer(!) value representing the day of the month of whatever date you provide" (end of quote).
There is no difference between NOW() and TODAY() as far as returning the day of the provided date.
I rest my case.

Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-05-29 13:14:09

Barry

Of course if you do just want a numeric value on a worksheet then the formula:

=DAY(NOW())

is by far the easiest solution.


2014-05-25 12:11:06

Barry

@ Micky,

For once, I have to disagree with your second sentence; setting the display format doesn't change the underlying value which will be the full date serial number and therefore performing any mathematical function on this expecting it to be just the day of the month with give an incorrect result.

You're correct in you're third sentence assuming the User wants a value rather than text. If the User wants a value then using the VALUE function on the result will convert the text to a number.


2014-05-24 15:22:40

Michael (Micky) Avidan

@Barry,
Ignore the first sentence, in my post, regarding the helper-column.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-05-24 11:53:25

Michael (Micky) Avidan

@@Barry,
To my opinion it is a waste to use an Helper column.
The same can be achieved by putting: =NOW() in the cell and format it with one of the day formats.
(dd / ddd / dddd)
In addition - the result of your suggestion is Pure Text and as such no calculations can be perfomed on it.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-05-24 05:06:05

Barry

If you only want this on a worksheet then you can use the formula:

=TEXT(NOW(),"d"))

using "dd" will include a leading zero for days 1-9;
"ddd" will give a short day name e.g. Mon
"dddd" will give the full day name e.g. Monday

The same is true for months just substitute "m" for "d"


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.