PDA

View Full Version : Solved: cutting date into variables



MPDK166
03-24-2011, 08:59 AM
I want to cut a date into the following variables, Day$, Month$ and Year$. How to do?

The date is a value in cell ("A1") and i want to chop into:

Dim Day$
Dim Month$
Dim Year$

The variable day and month always has goto be 2 figures (e.g. day: 03 or 16 or 24, etc..) and year must be 4 figures

For the variable year i can use the method:
Year$ = Right(Range("A1"), 4)

but how to get day$ and month$???

BrianMH
03-24-2011, 09:15 AM
You want these as strings right?


dim sDay as string
dim sMonth as string
dim sYear as string
dim dtmDate as date
dtmDate = range("A1").value
sDay = format(Day(dtmDate),"0000")
sMonth = format(Month(dtmdate),"00")
sYear = format(Year(dtmdate),"00")


If you just want these in the spreadsheet you can use the standard formula =Year(A1) etc.

MPDK166
03-24-2011, 09:58 AM
Cheers! :D