Escanaba
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!
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!
You need to pad the string: Right("0" & value, 8).
after importing, run an update query, something like
update tableName
set [dateField]=format([datefi eld],"0000 0000")
where len([dateField])=7
update tableName
set [dateField]=format([datefi
where len([dateField])=7
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.
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
/gustav
ASKER
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
Test.accdb
Sure , you can. It's called a concise and complete example.. just craft such a sample showing your problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
Thank you very much for your patience and assistance.
You are welcome!
/gustav
/gustav