?
Solved

Text to Date type

Posted on 2002-07-15
8
Medium Priority
?
219 Views
Last Modified: 2006-11-17
I have a text field “EndDate” in my table, half of data have format: mm/dd/yy the rest dd-MMM
I want to convert all data from text to date type format: mm/dd/yy.
Data in this field are like :
01-Jan
02-Jul
20-Dec
24-Dec
12/26/01
12/27/01
I want to put year 2001(01) at the end where it missing and then convert all data to date type.
May data in “EndDate “should look like :
01/01/01
07/02/01
12/20/01
12/24/01
12/26/01
12/27/01

Thanks

Taras

0
Comment
Question by:Taras
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 7155110
Then I would use Cdate(field)

In an update query use:

IIF(len(stringdate)<7,Cdate(stringdate&"-2000"),Cdate(stringdate))

Nic;o)
0
 
LVL 28

Accepted Solution

by:
TextReport earned 800 total points
ID: 7155125
You need to know about a couple of functions to do this and I would create a new field (always advisable as is a backupo before you start) Then you can update the new field with an update update query.

UPDATE mytable
SET mynewdate = iif(isdate(myolddatefield), cdate(myolddatefield),cdate(myolddatefield & "-2001")

Cheers, Andrew
0
 

Author Comment

by:Taras
ID: 7156081
Hi Andrew.
This is working fine.
Thanks for your help,
Taras.
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 

Author Comment

by:Taras
ID: 7156943
I have just one small problem Andrew it shows me year 2002 and I want 2001.
Any idea what I did wrong?
Taras.
0
 
LVL 28

Expert Comment

by:TextReport
ID: 7157434
Change the update query so it does a select with the update to part as another field and past some of the datefield and calculated field as an example of where they are going wrong, also, what version of Access is it?

Cheers, Andrew
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7157468
Looks like my comment has been invisible....

Nic;o)
0
 

Author Comment

by:Taras
ID: 7163267
Hi Nico5038.
I tried you answer and it shows 2001properly and that is what I need.
I will post this question again to allocate points to you.

Thanks Taras.

0
 
LVL 54

Expert Comment

by:nico5038
ID: 7163349
Thanks for the gesture ;-)

Both solution will work, but both have the same "problem" that an invalid date won't be processed correctly.
You need to be sure that no Nulls or other garbage is in this field.
From that point of view you should first run a select query like:
SELECT iif(isdate(myolddatefield), "Yes",IIF(IsDate(myolddatefield & "-2001"),"Yes","No")) AS DateOK From tblWithDate WHERE DateOK = "No";

This will show the problem fields.

Nic;o)
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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 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