Be the first user to complete this post
|
Add to List |
VBA-Excel: Date-Time Functions – Month(), Year() and MonthName()
Month()
Description:
The Month function takes Date as a parameter and returns a number between 1 and 12, that is the month of the date provided.
Format:
Month(strDate)
Arguments:
- strDate
- Mandatory
- Type: Date
- Date, whose Month need to be calculated.
Example:
Function FnMonth() Dim strDate strDate = "15-July-2013" MsgBox "Month of the " & strDate & " is -> " & Month(strDate) End Function
_____________________________________________________________________________________
MonthName()
Description:
The MonthName function takes numeric value as a parameter and returns a Month Name.
Format:
MonthName(intMonth[,blnAbbreviate])
Arguments:
- intMonth
- Mandatory
- Type: Numeric
- Value from 1 to 12 , whose Month Name need to be calculated. Like MonthName(3) will return “March”
- blnAbbreviate
- Optional
- Type: Boolean
- True value will provide the month name abbreviated, for example “July” will be abbreviated to “Jul”. default value is False
Example:
Function FnMonthName() Dim strDate Dim strResult strDate = "15-07-2013" strResult = "Full Month Name of the " & strDate & " is -> " & MonthName(Month(strDate)) & vbCrLf strResult = strResult & "Abbriviated Month Name of the " & strDate & " is -> " & MonthName(Month(strDate), True) MsgBox strResult End Function
_____________________________________________________________________________________________
Year()
Description:
The Year function takes Date as a parameter and returns a number represents the year.
Format:
Year(strDate)
Arguments:
- strDate
- Mandatory
- Type: Date
- Date, whose Year need to be calculated.
Example:
Function FnYear() Dim strDate strDate = "15-July-2013" MsgBox "Year of the " & strDate & " is -> " & Year(strDate) End Function
Also Read:
- VBA-Excel: Array Functions – Split()
- VBA-Excel: String Functions – strComp()
- VBA Excel - Cells, Ranges and Offset: Refer Range by using A1 Notations
- VBA-Excel : Strings Functions – Instr
- VBA-Excel: Date-Time Functions - Timer()