+ Reply to Thread
Results 1 to 4 of 4

Add zeroes within dates (NOT leading zeroes)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Add zeroes within dates (NOT leading zeroes)

    Hello. Question regarding strings that I can't wrap my head around.

    I have a list of dates in the following format: 200929 - this signifies February 9, 2009.

    What I need,however, is for each such value to have eight digits - meaning I must add zeroes to the month and/or day when they're single digits. For the example above, I need it to become 20090209

    Any advice on how to get started on tackling this? Any help would be appreciated.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,605

    Re: Add zeroes within dates (NOT leading zeroes)

    And what is for example 2009111 supposed to be? Jan 11th or Nov 1st ? How make the difference?

  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Add zeroes within dates (NOT leading zeroes)

    Very good point.

    How about if I do it before the concatenation then?

    If I have a column of the months/days, is there a simple If function I can include that adds a leading zero if the number of digits<2?

  4. #4
    Registered User
    Join Date
    06-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Add zeroes within dates (NOT leading zeroes)

    Have found that the REPT function does the job.

    So if given 12 in A1, the formula =REPT("0",2-LEN(A1))&A1. Now having some trouble evaluating that formula in VBA - am using Evaluate but coming up with errors. Any suggestions for this particular implementation?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1