+ Reply to Thread
Results 1 to 4 of 4

Date format problem when exporting to csv file

  1. #1
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Date format problem when exporting to csv file

    I have created a macro to export the contents of a query as a csv file, but when I open the csv file, the date is showing the date and time. I need it to only show the date as this csv file is uploaded to a parcel carrier's system that will only accept this field as dd/mm/yyyy.

    The date is created in an access table as a default value in the cell. The format is set to "Short date", the input mask to "00/00/000" and the default value to "Date()".
    The query field is also set the same. The date format appears correctly in both the table and the query, but when it is exported it somehow changes to date / time format.

    When I checked the cell format in the csv file it shows as a custom format "dd/mm/yyyy hh:mm"
    This file is overwritten every time I run the macro and in fact when I ran it for the first time, it created the csv file so it can't be due to a preformatted file problem.

    Would greatly appreciate any help on this - it's prevent us from automating our despatch processes.
    Last edited by MikeWaring; 11-30-2010 at 09:52 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Date format problem when exporting to csv file

    You could modify your macro to either reformat the date prior to save or to create a temporary CSV fule which you then process to create the real one, again with reformatting.

    To reformat, you could try using the LEFT function specifing the 10 left most characters which will trim off the time.

    If you need extra help, you will need to post a copy of the CSV file so that folk can see the format.
    Martin

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Date format problem when exporting to csv file

    In your query, create a new field with the expression =Int([your field name containing date]. Export this and not the current date field. Access saves dates as a serial number and formatting is only a presentation. It is not changing the value. This is especially important if you are having Access create the date as it will create it as a value similar to 43567.12387 which is the date and time in serial format. This is how it is saved. Formatting changes only how you see it.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Thumbs up Re: Date format problem when exporting to csv file

    Hi both, thanks for your suggestions. I'm working on another part of the database right now, but I'll try these solutions when I go back to that part of the project. I'm sure both will work, but if I have problems I'll open a new post.
    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1