Day VBA function – How to calculate day of month from date

1. Day VBA function – Description

The Day VBA function returns a number that represents the day of the month of a given date. So if we want Excel VBA to return to us numbers corresponding to the next days of the month, we should use this function. It should be remembered that the date from which we want to obtain the number of the day of the month should be taken from the variable or saved in the VB code in the date format, i.e. YYYY-MM-DD .

2. VBA Day function – Syntax

Day (Date)

Date : The date from which we want to get the next number corresponding to the day of the month. The date should be in the YYYY-MM-DD format .

Function return: Integer / Numeric value.

3. VBA Day function – Example

How to use the Day function in VBA Excel? Below is an example of using the Day function in the VisualBasic Editor.

Sub DayFunctionExample ()

MsgBox Day ("2017-12-31")

Dim DatDate As Date
DatDate = Date
MsgBox Day (DatDate)

MsgBox Day (Date)

Range ("A1") = Day ("2018-05-31")

End Sub
Excel VBA functions - Day VBA function
Excel VBA functions – Day VBA function

4. VB Day function – Additional information

  • The date from which we want to obtain the next number of the day of the month should have the Date data type or be saved in the YYYY-MM-DD format.

5. Day VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions .

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: