Solved

Access 2010 Changing String to Date with Leading Zero

Posted on 2017-05-18
11
28 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
You need to pad the string: Right("0" & value, 8).
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
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
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
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
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
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
Thank you very much for your patience and assistance.
0
 
LVL 50

Expert Comment

by:Gustav Brock
You are welcome!

/gustav
0

Featured Post

Technology Partners: 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!

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

737 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