-
Solved: cutting date into variables
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$???
-
You want these as strings right?
[vba]
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")
[/vba]
If you just want these in the spreadsheet you can use the standard formula =Year(A1) etc.
-
Cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules