Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel vba get month from Date object

Tags:

excel

vba

I have a cell that gets filled with a date value. I then store it in a variable.

Sub dateTest()
    Dim min_date As Date
    min_date = ThisWorkbook.Worksheets("setup").Cells(22, 5).value

    MsgBox (min_date)
End Sub

However, I would like to get a month and a day separately from that object. How to do it?

like image 841
Ans Avatar asked Nov 09 '17 15:11

Ans


1 Answers

Month() and Day() are the functions that you need:

MsgBox (Month(minDate))
MsgBox (Day(minDate))
  • Microsoft Month Reference

  • Microsoft Day Reference


Another way is to use the Format function:

MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")
like image 182
Vityata Avatar answered Oct 16 '22 17:10

Vityata