Results 1 to 4 of 4
  1. #1
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    57

    Formatting Dates in a Query

    Hi,



    I've set up a make table query to change one table into another. However I'm stuck on one field, is there a way to change the way a date is formatted as part of this query? It's currently down as 2017:11:20 17:04:01 but I would like it to be like 20/11/2017, is this possible? I can format it in excel before importing, by text to columns to get rid of the time and then changing the : to a / but this is a lot of effort! If I do this before I import I can then put this is in the query. BOOKINGDATE: Format([Registration Date],"dd/mm/yyyy"). Any help would be appreciated

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If your entries are like "2017:11:20 17:04:01", and you just want to get the valid date out of it in a query, use this calculated field:
    Code:
    CDate(Replace(Left([Registration Date],InStr([Registration Date]," ")-1),":","/"))
    Note that the FORMAT function returns a string, not a date. So you typically wouldn't worry about the formatting of the date in the calculation, you would handle that in the Table or Query Formatting property.

    If you had wanted to return a String and not a Date, then you could wrap that whole calculation in the Format function, i.e.
    Code:
    Format(CDate(Replace(Left([Registration Date],InStr([Registration Date]," ")-1),":","/")),"dd/mm/yyyy")
    Just note that in a Make Table query, the first calculation will set up a Date Data Type while the second will set up a Text Data Type.

  3. #3
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    57
    Great the second one worked, thank you!

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome.

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

Similar Threads

  1. Conditional Formatting with dates
    By drewdrew in forum Access
    Replies: 3
    Last Post: 01-06-2016, 04:48 AM
  2. Help formatting calendar dates
    By cmb in forum Modules
    Replies: 1
    Last Post: 10-10-2014, 11:06 AM
  3. Conditional Formatting on Dates
    By jpicard in forum Access
    Replies: 12
    Last Post: 11-02-2011, 03:36 PM
  4. Using Conditional Formatting & Dates
    By djclntn in forum Forms
    Replies: 14
    Last Post: 04-12-2011, 07:04 PM
  5. Formatting dates
    By John Southern in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 11: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