Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Date-Time Functions – DateSerial()

Description:

The DateSerial() function returns the Date type based on the parameters provided (year, month and date).

Format:

DateSerial(year,month,day)

Arguments:
  • Year
    • Manda­tory
    • Type: Numeric or Any Numeric Expression
    • Between 100 and 9999, values between 0-99 will be considered as 1900-1999
  • Month
    • Manda­tory
    • Type: Numeric or Any Numeric Expression
    • If it’s greater than 12, than respective number will be added to the date, Example say 13, mean month will be January and year will be increased by one.
  • Date
    • Manda­tory
    • Type: Numeric or Any Numeric Expression
    • If it’s greater than 31 and month is 12, than respective number will be added to the date, Example say 44, mean month will be January and year will be increased by one and date will be 13.

Example:

Function FnDateSerial()

   Dim varYear

   Dim varMonth

   Dim varDate

    varYear = "2013"

    varMonth = "12"

    varDate = "44"

    

    strDate = DateSerial(varYear, varMonth, varDate)    

  MsgBox "Date is " & strDate

End Function

The Date­Se­r­ial() func­tion returns the Date type based on the para­me­ters pro­vided (year, month and date).
DateSerial()



Also Read:

  1. VBA Excel - Cells, Ranges and Offset: Refer Range by using A1 Notations
  2. VBA-Excel: Get all the WeekDays or Working days in Specified Date Range, (excluding Satudays and Sundays)
  3. VBA-Excel: Array Functions – Filter()
  4. VBA-Excel : Strings Functions – Instr
  5. VBA-Excel: String Functions – strComp()