Ans
Ans

Reputation: 1234

Excel vba get month from Date object

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?

Upvotes: 8

Views: 41283

Answers (1)

Vityata
Vityata

Reputation: 43595

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

MsgBox (Month(minDate))
MsgBox (Day(minDate))

Another way is to use the Format function:

MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")

Upvotes: 18

Related Questions