Consulting

Results 1 to 3 of 3

Thread: Solved: cutting date into variables

  1. #1
    VBAX Regular
    Joined
    Mar 2011
    Posts
    52
    Location

    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$???

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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.

  3. #3
    VBAX Regular
    Joined
    Mar 2011
    Posts
    52
    Location
    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
  •