Results 1 to 9 of 9
  1. #1
    unslog is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8

    Convert text date to date value

    Hi

    i have a linked table from ODBC , and trying to run a query.

    One of the columns in the query is outputting date in this format 20100914

    it should be outputting in this format dd/mm/yyyy

    in the access design view, I have tried to select the field in question and prefix with cDate([datefield]) datefield being the field from the table containing the serial date. this doesn't work , the system changes to Expr1: CDate([datefield])

    In the table this field has been as TEXT, and I cannot change to date.

    Please can someone help as I need to add criteria to this field



    e.g. >=Now()+"100"

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You can use this:

    MyDate:Format(DateSerial(Left([datefield],4),Mid([datefield], 5,2),Right([datefield],2)),"dd/mm/yyyy")

    And the criteria should be able to be

    >=DateAdd("d", 100, Date())

    (don't use NOW unless you need time included)

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    You need to change it to a date Use CDate(mid(columnname,5,2) & "/" & right(columnname,2) & "/" & left(columnname,4))

    This will give you a date in the format mm/dd/yyyy Then you can display it in any manner you want using format([converteddate],"dd/mm/yyyy")

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Bob beat me. plus I like his solution better. Mine takes 2 steps where his is done in 1.

  5. #5
    unslog is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8
    Thanks guys in particular BOB, worked a treat.

    I want to filter on all dates between today and today + 100days on this new Date column (MyDate)

    I have tried >=DateAdd("d", 100, Date()) , but it returning dates in 2009

    Also when I sort on this column , it doesn't appear to be sorting dates correctly e.g.

    11/10/2011
    11/10/2011
    11/11/2010
    11/11/2011


    Can you help?

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    I was afraid that might happen because FORMAT changes things to a string.

    So, you should just create a separate field (doesn't have to be displayed) for the criteria. Use the same code I gave you but without the Format part. And then the criteria I gave you should work. Also sort on that field instead.

  7. #7
    unslog is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8
    Hi Bob
    the sort function is now working.

    here are the settings on this column;
    Field: Datefield
    Table:PUBLIC_HEADER_TABLE
    Sort: Descending
    Criteria: >=DateAdd("d",100,Date())
    Show: Unticked

    Now, the column MyDate is visiable with no criteria or sort, however the dates on query run still appear to be outside filter e.g. 26/02/2010 , 03/01/2011,25/09/2010. No other criteria is being defined on this query


    The PC date is set to 02/02/2012

    Not sure why it is not why MyDates column is not displaying all dates between today and today + 100days ?

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You show the criteria on the datefield but it should be:

    Field: DateSerial(Left([datefield],4),Mid([datefield], 5,2),Right(datefield],2))
    Table:
    Sort: Descending
    Criteria: >=DateAdd("d",100,Date())
    Show: Unticked

  9. #9
    unslog is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8
    I think this has worked. Need to look at it with fresh eyes in the morning.
    Thank you very much

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

Similar Threads

  1. Convert date to weekday overview
    By LarsBoer in forum Forms
    Replies: 3
    Last Post: 09-14-2011, 07:25 AM
  2. Replies: 1
    Last Post: 08-07-2011, 07:58 AM
  3. Number convert to date
    By Argus in forum Programming
    Replies: 1
    Last Post: 08-05-2009, 02:21 PM
  4. how to convert week number to date range
    By qwang1115 in forum Access
    Replies: 1
    Last Post: 02-13-2009, 11:35 AM
  5. Convert string to date
    By ~SwAmPdOnKeY~ in forum Queries
    Replies: 4
    Last Post: 09-11-2008, 07:19 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