We help IT Professionals succeed at work.

MS Access how to import string into Date/Time

AndyC1000
AndyC1000 asked
on
Dear all,

I have an excel file that I'm importing into access.  One of the columns (fields to import) contains date information i.e. 01/05/2012 00:00:00 Tue.  When I import it into Access as a Date with Time I end up with import errors and it doesn't work.  I tried to change the format of the excel cells to Date but it makes no difference.

My next step is to link records by date, this table and another table where the Date is separate fields Month, Day, Timestep. The timestep is an integer from 1 to 48 for each day (half hourly data for one day).

How do I import this data into the database?  I don't need the actual day information (i.e. Tue).  Is it possible to parse the date using VB script or a macro into Year, Month, Day, Hour, Minute, Second etc.? Or include the timestep for the time?

Thanks
Comment
Watch Question

Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
First import or link the Excel file where you specify the field as text.
Then pull the data via a query using the linked or imported table as source.
In this query, convert the string to a date using this expression:

    TrueDate: CDate(Mid([YourTextDateField],1,19))

If some records contains Null for this field, use CVDate:

    TrueDate: CVDate(Mid([YourTextDateField],1,19))

Also convert other fields as needed.
Now use this query as source when you proceed.

/gustav
Distinguished Expert 2017
Commented:
If the import is temporary, then stick with the query solution.  However, if the import is permanent, I would store the reformatted data in a proper date/time column.  Once the update is successful, then delete the original text column.