?
Solved

Access 2010 Changing String to Date with Leading Zero

Posted on 2017-05-18
11
Medium Priority
?
50 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 51

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 51

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 51

Expert Comment

by:Gustav Brock
ID: 42142396
You are welcome!

/gustav
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

764 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