Link to home
Start Free TrialLog in
Avatar of Escanaba
EscanabaFlag for United States of America

asked on

Access 2010 Changing String to Date with Leading Zero

Hello,

The Excel extract I'm linking to has a date column in string format (ex. 12312016).  Furthermore, when it gets to the first 9 months of the year it does not add the leading zero (ex. 1152017 instead of 01152017).  How do you recommend converting this information into a date with a leading zero for the first 9 months?

Thanks!
Avatar of ste5an
ste5an
Flag of Germany image

You need to pad the string: Right("0" & value, 8).
after importing, run an update query, something like

update tableName
set [dateField]=format([datefield],"00000000")
where len([dateField])=7
Avatar of Escanaba

ASKER

I should of noted that I am really new to Access so with either suggestion can you guide me as to where those formulas should be added to the query?
what is the name of the table?
what is the name of the field with date?

better if you can upload a copy of your db.
Use a query like this:

Select 
    *,
    CDate(Format(Right("0" & [YourStringDateField], 8), "@@/@@/@@@@")) As TrueDate
From
    YourTable

Open in new window

/gustav
Unfortunately I cannot attach the database due to confidential data.  The table name is CtResults_Masters and the field name containing the date is named 'Date'.  Note that this is a linked table and the date field is coming in as a number data type.  It will not allow me to change the data type.  If I change the format to mm/dd/yyyy it changes the data.  So 12262016 becomes 12/30/1899.  I've attached a sample database with just the date field so any guidance on putting recommendations in place using the sample file would be helpful.
Test.accdb
Sure , you can. It's called a concise and complete example.. just craft such a sample showing your problem.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ste5an - oddly enough I thought the sample provided was sufficient.  Apparently not far off the mark based on Gustav's ability to provide a solution.
Thank you very much for your patience and assistance.
You are welcome!

/gustav