Results 1 to 7 of 7
  1. #1
    tiger6115 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    9

    Need to Convert String to m/d/yyyy Format

    I am looking to automate an import of an excel worksheet provided by an insurance company. Unfortunately the date fields on the worksheets are not formatted correctly. The dates are displayed as 9192018 instead of 9/19/2018. I have tried to format the dates while importing in access but it converts the dates into nonsense (generic 12PM Time, 1499 dates, etc.) I have also tried to format the dates in excel prior to importing them in Access but that doesn't work either (It shows nothing but ##### and the error says "dates and times that are negative....").

    Is there a way to format all date values that are mddyyyy to m/dd/yyyy automatically while importing to access? Thank you in advance for any help/direction you can provide.


    A few examples of the dates:

    PolExpDt
    1012019
    12312018
    1012019
    9012018
    9182018
    10042018
    11202018
    9012018
    9062018
    11042017




  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Can you always depend on year part of 4 digits and day part of two digits? If not, no manipulation can reliably convert to valid date.

    Let x represent your field.

    DateSerial(Right(x,4), Left(x,Len(x)-6), Mid(Right(x,6),1,2))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    I would probably format each value to eight characters, so you always have a 2 digit month, 2 digit day and 4 digit year, then use a combination of Left, Mid and Right functions to break it up and add in the slash charaters, then typcast the result back to a date;

    CDate(Left(Format([YourField],"00000000"),2) & "/" & Mid(Format([YourField],"00000000"),3,2) & "/" & Right(Format([YourField],"00000000"),4))

    Others may have better suggestions.

  4. #4
    tiger6115 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    9
    June7 From the 1500+ records on this one worksheet, i can see that the year is consistently 4 digits yyyy and the days are consistently 2 digits. I'm assuming that instead of Access' automated import process, i would need to create VBA code to initiate the import process and i would include the code you provided.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Quite possibly the case. Or try the manipulation in the Excel.

    =DATEVALUE(LEFT(A1,LEN(A1)-6) & "/" & MID(RIGHT(A1,6),1,2) & "/" & RIGHT(A1,4))

    Then format the column.

    Or Don't use DATEVALUE and just build a string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    tiger6115 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    9
    Thanks June7, your formula worked to format the dates perfectly and works as a quick and dirty workaround. I'll work on automating it by making some Macros in Excel. I'll cleanup the data before importing into Access.

    Beetle, thanks for your suggestion. When i have more time, I'll give it a try in Access.

  7. #7
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    Actually, the first suggestion by June7 using DateSerial is a bit cleaner and simpler to write, so on the Access side I would probably use that.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-12-2014, 09:48 PM
  2. Replies: 3
    Last Post: 01-03-2014, 03:14 AM
  3. CDate function to convert from dd.mm.yyyy format
    By GregTheSquarePeg in forum Queries
    Replies: 7
    Last Post: 10-11-2013, 07:11 AM
  4. Convert to MMM/YYYY
    By Brian62 in forum Queries
    Replies: 10
    Last Post: 08-31-2009, 04:54 PM
  5. Replies: 1
    Last Post: 06-11-2009, 05:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums