Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

When you export date fields to text, the time format is included Abstract


Moderate: Requires basic macro, coding, and interoperability skills.


This article applies only to a Microsoft Access database (.mdb).


For a Microsoft Access 2000 version of this article, see 209268 .

↑ Back to the top


Symptoms

When you export a table that includes a Date/Time field to a text file, Microsoft Access automatically adds the time format to the date in the exported text file. The Date/Time field appears in the text file in mm/dd/yy hh:nn:ss format.

↑ Back to the top


Cause

Access stores date and time values for all date fields. When you export the data to a text file, Access exports both the date and the time. If there is no data for the time portion of a date, the time appears as 0:00:00, indicating 12 A.M.

↑ Back to the top


Resolution

There are two methods to work around this behavior.

Method 1

Create a query that has a calculated field to format the Date/Time field appropriately, and then export the results of the query. To do so, follow these steps

  1. Open the sample database Northwind.mdb.
  2. Create the following new table in Design view:

    Table: TestDate
    --------------------
    Field Name: Birthday
    Data Type: Date/Time
  3. Save the table, and then close it. You do not have to create a primary key.
  4. Open the table in Datasheet view, add the following record, and then close the table:

    04/19/93
  5. Create the following new query based on the TestDate table:


    Query: ExportDates
    ------------------------------------------------
    Type: Select Query

    Field: Birthday2: Format([Birthday], "mm/dd/yy")
    NOTE: The calculated field name cannot match the name of any other field that is included in the query.
  6. Save the query, and then close it.
  7. Export the query.

Method 2

You can have Access create a fixed-width text file by using the "Text (Fixed Width)" export format. By using this method, you can set the size of the Date/Time field to 10 characters in the Export Specification dialog box. This will truncate the time portion of the Date/Time field when the file is exported.


NOTE: This method assumes that you have the Four Digit Years and Leading Zeroes in Dates options selected in the Export Specification dialog box.


NOTE: Most common text exports require the data is delimited by using the Text (Delimited) format. Method 2 is not useful in these cases.

↑ Back to the top


More Information

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.
  2. Create the following new table in Design view:

    Table: TestDate
    --------------------
    Field Name: Birthday
    Data Type: Date/Time
  3. Save the table and close it. You do not need to create a primary key.
  4. Open the table in Datasheet view, add the following record, and then close the table:

    04/19/93
  5. Select the TestDate table in the Database window, and then click Export on the File menu.
  6. In the Export Table dialog box, select Text Files in the Save as type box, and then click Save.
  7. In the Export Text Wizard, note that the data appears in the Sample export format box as 04/19/93 0:00:00.
  8. Click Cancel to return to the Database window.

↑ Back to the top


References

For more information about exporting data to other file formats, click Microsoft Access Help on the
Help menu, type exporting data, data formats in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: kbformat, kbsweptsoltax, kbbillprodsweep, accrtmpublic, kbaccess10ready, kbprb, kb, kbarchive

↑ Back to the top

Article Info
Article ID : 291245
Revision : 3
Created on : 4/17/2018
Published on : 4/19/2018
Exists online : False
Views : 185