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 func­tion takes Date as a para­me­ter and returns a num­ber between 1 and 12, that is the month of the date provided.

Format:

Month(strDate)

Arguments:
    • str­Date
      • Manda­tory
      • Type: Date
      • Date, whose Month need to be calculated.

Exam­ple:

Function FnMonth()

  Dim strDate

  strDate = "15-July-2013"    

  MsgBox "Month of the " & strDate & " is -> " & Month(strDate)    

End Function
Month()

Month()

_____________________________________________________________________________________

Mon­th­Name()

Description:

The Mon­th­Name func­tion takes numeric value as a para­me­ter and returns a Month Name.

Format:

MonthName(intMonth[,blnAbbreviate])

Arguments:
  • int­Month
    • Manda­tory
    • Type: Numeric
    • Value from 1 to 12 , whose Month Name need to be cal­cu­lated. Like MonthName(3) will return “March”
  • blnAb­bre­vi­ate
    • Optional
    • Type: Boolean
    • True value will pro­vide the month name abbre­vi­ated,  for exam­ple “July” will be abbre­vi­ated to “Jul”. default value is False

Exam­ple:

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.

Mon­th­Name()

_____________________________________________________________________________________________

Year()

Description:

The Year func­tion takes Date as a para­me­ter and returns a num­ber rep­re­sents the year.

Format:

Year(strDate)

Arguments:
  • str­Date
    • Manda­tory
    • Type: Date
    • Date, whose Year need to be calculated.

Exam­ple:

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: