Results 1 to 7 of 7
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Convert Text Column To Date

    I have a text column in a table that should actually be a date. Well I can't go back and change the table so how can I format a text column to display as a date mmddyyyy in an access query?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Do you just need to change the way it looks (the format), or do you actually need it to be a date field so you can perform calculations on it?
    What does the data look like right now in the Text field?

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    As long as the text is already formatted as a date, you can use CDate() to convert it in realtime. Otherwise, you'll need to massage the output to look like a date before using the function.

    Show us a couple of examples if using CDate() doesn't work and we'll see what we can do

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Why can't you fix the table?
    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.

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by JoeM View Post
    Do you just need to change the way it looks (the format), or do you actually need it to be a date field so you can perform calculations on it?
    What does the data look like right now in the Text field?

    Yes, I just need to change the look. It shows in the table as 1162015 I need it to show as 1/16/2015.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Consistency is critical in manipulating strings. Months and days can be 1 or 2 digits. This would be fairly easy if the text were like: 01162015, 11052015, 04072015 (note the placeholder zeros). How should we know that 1112014 is 1/11/2014 or 11/1/2014? 1222014 is 1/22/2014 or 12/2/2014? I don't know how many more there could be.

    Need to fix the data then fix the table.

    Fixing the data, if there is a lot, will likely be a long, tedious effort. Any strings less than 8 characters will have to be adjusted with placeholder zeros. Could assume the 6-character strings should have two zeros and a calculation could deal with that. It's the 7-character values that get tricky. For some the mon/day will be obvious. For instance, 1312014 cannot be 13/1/2014, 9202014 cannot be 92/0/2014. Again, another calc can identify these invalid months/days and construct a correct date value.

    Fix the 6-character values first. Then do another pass to calc and fix some of the 7-character values. What's left will probably need case-by-case review and manual edit.
    Last edited by June7; 01-16-2015 at 05:54 PM.
    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.

  7. #7
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    June7 is absolutely right.

    Unless the month is the ONLY part that can be a single digit, I think you're out of luck.

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

Similar Threads

  1. Convert Short text column to date ms access
    By SameerSarswat in forum Access
    Replies: 3
    Last Post: 10-09-2014, 10:42 AM
  2. Convert Text String to Date in SQL
    By kestefon in forum Access
    Replies: 2
    Last Post: 12-04-2013, 03:33 PM
  3. Replies: 3
    Last Post: 09-11-2013, 09:49 AM
  4. Replies: 8
    Last Post: 02-28-2013, 02:21 PM
  5. Convert text date to date value
    By unslog in forum Access
    Replies: 8
    Last Post: 02-01-2012, 12:22 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