Excel DAY Function
The Excel DAY function returns the day from a specified date
Example: Excel DAY Function
=DAY("15/03/2017")
|
Result in cell C5 (15) - in this example we are inserting the date directly into the Excel DAY function, which returns the day component of the date.
|
METHOD 2. Excel DAY Function using links
EXCEL
=DAY(B5)
|
Result in cell C5 (15) - in this example we are referencing to a cell that contains a date and the Excel DAY function returns the day component of the date.
|
METHOD 3. Excel DAY function using the Excel built-in function library with hardcoded values
EXCEL
Formulas tab > Function Library group > Date & Time > DAY > populate the input box
=DAY("15/03/2017") Note: in this example we are manually populating the input box with the date from which we want to return the day component. If entering the date directly into the input box, as per this example, we need to use the double quotation marks. |
METHOD 4. Excel DAY function using the Excel built-in function library with links
EXCEL
Formulas tab > Function Library group > Date & Time > DAY > populate the input box
=DAY(B5) Note: in this example we are populating the input box with a cell reference that captures the date from which we want to return the day component. |
Sub Excel_DAY_Function_Using_Hardcoded_Values()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("DAY")
'apply the Excel DAY function
ws.Range("C5") = Day("15/03/2017")
ws.Range("C5") = Day("15/03/2017")
End Sub
OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named DAY.
Worksheet Name: Have a worksheet named DAY.
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
METHOD 2. Excel DAY function using VBA with links
VBA
Sub Excel_DAY_Function_Using_Links()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("DAY")
'apply the Excel DAY function
ws.Range("C5") = Day(ws.Range("B5"))
ws.Range("C5") = Day(ws.Range("B5"))
End Sub
OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named DAY.
Date: If using this exact VBA code, which sources the date from cell ("C5"), you will need to capture the date from which you want to extract the day in cell ("C5").
Worksheet Name: Have a worksheet named DAY.
Date: If using this exact VBA code, which sources the date from cell ("C5"), you will need to capture the date from which you want to extract the day in cell ("C5").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Date: Select the date from which you want to extract the day by changing the cell reference ("C5") to any cell in the worksheet that contains the date and doesn't conflict with the formula.