Solved

Access 2010 Changing String to Date with Leading Zero

Posted on 2017-05-18
11
39 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 34

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 50

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 34

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 50

Accepted Solution

by:
Gustav Brock earned 500 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 50

Expert Comment

by:Gustav Brock
ID: 42142396
You are welcome!

/gustav
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

687 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