+ Reply to Thread
Results 1 to 7 of 7

Date converting YYMMDD

  1. #1
    Registered User
    Join Date
    10-01-2007
    Posts
    23

    Date converting YYMMDD

    I have a list of values in column A that represent dates. They are in the format YYMMDD. For example, march 31st 2007 is recorded in its cell as 070331.

    I have another spreadsheet with two cells where the user enters a year and a quarter. Quarter 1 represent Jan 1 - Mar 31, Quarter 2 represents Apr 1 to Jun 30, and so on.

    Currently my code grabs the user defined year and quarter and converts it to the corresponding date. For example: if the user enters 07 as the year and quarter 3, two variables get defined (startDate = 7/1/07, endDate = 9/30/07).

    Now is where everything I have gets into a huge mess of if statements. As you can see, the values I am trying to find (format YYMMDD) based off of the startDate and endDate are not in the same format. Currently my mess of if statements break apart the startDate and endDate variables and reassemble them to mirror the format YYMMDD. However, I run into issues when there is a leading zero in a month or day. I have temporarly gotten around this by just throwing more if statements at my code, but it is getting extremely difficult to read and modify.

    My question is this:

    Is there a simple way I can convert the format MM/DD/YY to YYMMDD without the method that I am using above? I figured it would be fun to attempt this conversion using logic. Its not fun.
    Last edited by paulmezick; 10-26-2007 at 04:01 PM.

  2. #2
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    Is it important the the actual values be in that order in the cells or can this be accomplished by simply changing the date format? Just trying to offer the simple solution first.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  3. #3
    Registered User
    Join Date
    10-25-2007
    Posts
    6

    Not VBA, but is it needed?

    Is the date entered directly into a cell?

    if so, don't grab this cell, grab the adjacent cell.

    eg.

    IF A1 =
    MM/DD/YY YYMMDD
    IF A1 = 08/06/07 then B1=A1 070608


    in cell B1 format the cell
    format - format cells - number tab - custom - enter YYMMDD

  4. #4
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    you could also use this formula

    =TEXT(D12,"yy")&TEXT(D12,"mm")&TEXT(D12,"dd")

    Where D12 contains the date in ANY format.

  5. #5
    Registered User
    Join Date
    10-01-2007
    Posts
    23
    Quote Originally Posted by carbon
    Is the date entered directly into a cell?

    if so, don't grab this cell, grab the adjacent cell.

    eg.

    IF A1 =
    MM/DD/YY YYMMDD
    IF A1 = 08/06/07 then B1=A1 070608


    in cell B1 format the cell
    format - format cells - number tab - custom - enter YYMMDD
    This works if I am converting from mm/dd/yy to yymmdd, however I can't get this method to work if I am converting from yymmdd to mm/dd/yy.

    I am trying to convert cells that are formatted as Text, in order to preserve leading 0's, to mm/dd/yy.

    For example: 071003 (formatted as text) would convert to 10/03/07. I've tried the above suggestions and can't get this to work.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Select the column with the dates, goto Data>Text to columns... and on the third step select YDM from the column data format dropdown.

  7. #7
    Registered User
    Join Date
    10-01-2007
    Posts
    23
    This worked great. Thanks a lot!

+ 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