Export date field via a query to an Excel file

I am exporting a query result to an Excel file.  The query contains a date field.  The date field is Short Date by default.  But when for example 3/14/2017 gets exported to the Excel file it looks like 3/14/2017  12:00:00 AM

Why is this happening?

The export VBS code is:

DoCmd.TransferText acExportDelim, , "qryRecords", strCSV & Environ("userProfile") & "\Desktop\" & "Records " & Format(Now, "mm-dd-yyyy_hh-nn") & ".csv", True

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:

MS Access export the date value, not the format. Then MS Excel give it a default format.

If you want a specific format, convet to string by using the format() function in your query.
Paul Cook-GilesAccess/VBA/SQL Database DeveloperCommented:
Even though the table is formatted for ShortDate, the time value is still part of the entry;  it's just 0.  If you format the field in the query you're exporting like this:  Format(DateField, "M/D/YYYY")  as FormattedFieldName   the value exported should be just the date.  (Note that "M/D/YYYY" will return 1/3/2018 or 11/15/2018;  "MM/DD/YYYY" will return 01/03/2018 or 11/15/2018.  :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
All you need is to apply a format (like m/d/yyyy ) to the column in the worksheet holding the date values.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.