?
Solved

Access 2010 Changing String to Date with Leading Zero

Posted on 2017-05-18
11
Medium Priority
?
65 Views
Last Modified: 2017-05-19
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!
0
Comment
Question by:Escanaba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 35

Expert Comment

by:ste5an
ID: 42141191
You need to pad the string: Right("0" & value, 8).
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 42141199
after importing, run an update query, something like

update tableName
set [dateField]=format([datefield],"00000000")
where len([dateField])=7
0
 
LVL 1

Author Comment

by:Escanaba
ID: 42141253
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?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 42141396
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.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 42141696
Use a query like this:

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

Open in new window

/gustav
0
 
LVL 1

Author Comment

by:Escanaba
ID: 42142275
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
0
 
LVL 35

Expert Comment

by:ste5an
ID: 42142288
Sure , you can. It's called a concise and complete example.. just craft such a sample showing your problem.
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 42142293
Use this query:

SELECT 
    tbl_date.date,
    CDate(Format(Right("0" & CStr([date]), 8), "@@/@@/@@@@")) As TrueDate
FROM 
    tbl_date;

Open in new window

/gustav
Test--1-.accdb
0
 
LVL 1

Author Comment

by:Escanaba
ID: 42142381
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.
0
 
LVL 1

Author Closing Comment

by:Escanaba
ID: 42142382
Thank you very much for your patience and assistance.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 42142396
You are welcome!

/gustav
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question