Solved

Text to Date type

Posted on 2002-07-15
8
207 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 200 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

726 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