Results 1 to 7 of 7
  1. #1
    MI_XD is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    3

    Trouble with Update Query - Convert numbers to Date Format

    Having trouble with an Update Query. Using two text format fields, trying to change a DOB field to NewDOB field formatted using xx/xx/xx.
    DOB field examples:
    92115


    111015
    81714
    102315

    Using this formula I get bad results, as they do not seem to recognize all the numbers.

    IIf(("Len[DOB]=5"),Left([DOB],1),Left([DOB],2)) & "/" & IIf("Len[DOB]=5",Mid([DOB],2,2),Mid([DOB],3,2)) & "/" & Right([DOB],2)

    Examples of results I am getting:
    Click image for larger version. 

Name:	access.jpg 
Views:	10 
Size:	50.2 KB 
ID:	23543

    Any help on this formula or problem would be appreciated.
    Thanks,

    Bob
    Win 10 Pro
    Access 2016

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    this

    ("Len[DOB]=5")

    should be

    Len([DOB])=5

    i.e.

    IIf((Len([DOB])=5,......

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Do you realize that MSAccess provides a Date/Time datatype to be used with dates?
    And a series of related functions to manipulate dates.

    Here is info about Iif
    Good luck.

  4. #4
    MI_XD is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    3
    Quote Originally Posted by Ajax View Post
    this

    ("Len[DOB]=5")

    should be

    Len([DOB])=5

    i.e.

    IIf((Len([DOB])=5,......
    I thought it was strange, but the auto formatting changed it to have the "" at one point. Guess when I was making changes. I had tried all variations, but it never seemed to work.

    Just made the corrections so it is formatted as Len([DOB])=5, and it WORKED!

    Thanks, Ajax!

  5. #5
    MI_XD is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    3
    Quote Originally Posted by orange View Post
    Do you realize that MSAccess provides a Date/Time datatype to be used with dates?
    And a series of related functions to manipulate dates.

    Here is info about Iif
    Good luck.
    Orange,
    Yes I do, but I needed to get the date from the text string form that the data was imported as, into a date format with the "/" marks.

    Thanks!

  6. #6
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Just wondering... What if DOB is "11109"? Is it 1/11/09 or 11/1/09?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also could use
    Code:
    Left([DOB], IIf(Len([DOB]) = 5, 1, 2)) & "/" & Mid([DOB], 2, IIf(Len([DOB]) = 5, 2, 3)) & "/" & Right([DOB], 2)
    A little shorter, but easier to read?? (maybe??)

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

Similar Threads

  1. Replies: 1
    Last Post: 03-18-2015, 09:17 AM
  2. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  3. Replies: 8
    Last Post: 01-16-2013, 02:10 PM
  4. Convert date format yyyymmdd for datediff
    By TEN in forum Programming
    Replies: 1
    Last Post: 06-17-2009, 09:35 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