Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

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
      • Manda­tory
      • 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
Month()

Month()

_____________________________________________________________________________________

MonthName()

Description:

The MonthName function takes numeric value as a parameter and returns a Month Name.

Format:

MonthName(intMonth[,blnAbbreviate])

Arguments:
  • intMonth
    • Manda­tory
    • 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

 
The MonthName function takes numeric value as a parameter and returns a Month Name.

MonthName()

_____________________________________________________________________________________________

Year()

Description:

The Year function takes Date as a parameter and returns a number represents the year.

Format:

Year(strDate)

Arguments:
  • strDate
    • Manda­tory
    • 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
The Year function takes Date as a parameter and returns a number represents the year.

Year()

 

You may also like...

Leave a Reply

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

%d bloggers like this: