Consulting

Results 1 to 5 of 5

Thread: Solved: parsing dates

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Solved: parsing dates

    [vba]Dim mydate As Date
    mydate = Date
    mymonth = Left(mydate, 2)[/vba]
    mydate = "8/10/2009"
    mymonth = "8/"

    Is there a way to force the month to have 2 numeral spaces (force a leading zero)?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Tom,

    If you are just looking for the Month Try:
    [vba]
    Dim mydate As Date
    mydate = Date
    mymonth = Month(mydate)
    [/vba]
    or depending on your needs
    [vba]mymonth = Month(Date)[/vba]
    I would do this:
    [vba]
    strMonth = IIf(Month(Date) < 10, "0" & CStr(Month(Date)), CStr(Month(Date)))
    [/vba]

    HTH

    EDIT: Fixed an error Tommy

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    [VBA]mymonth = Format(mydate, "mm")[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    thanks guys. didn't have time to try it out today but i'll mark it solved.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Heh, it seems I always try to do things the hard way. Thanks again.
    Office 2010, Windows 7
    goal: to learn the most efficient way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •