Solved

converting dates to 1900+ rather than 2000+

Posted on 2002-04-12
7
222 Views
Last Modified: 2012-05-04
I am importing data from a text file that has mixture of dates in long format i.e. dd/mm/yyyy and short dates i.e. dd/mm/yy in one field. The field is a date of birth field, and it has people in it with date of birth before 1930. When i change the field to a date format, it changes there date of births to 2000+.
Can anyone tell me how to convert to dates before 1930.
0
Comment
Question by:Easty
  • 3
  • 2
  • 2
7 Comments
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Which version of Access?  If it's 97 or later, there is nothing you can do about it in terms of changing the import behavior.

Couple of things then:
1. Change the input file.

2. Change the data after import with a query.

3. Import the file using a custom VBA procedure and modify the dates as they are read in.

 #3 is probably the best (but slightly more work - however you get complete control over the process), but I don't know if your importing into an existing table with data or not.  Also, I don't know if you can change the input file.

Jim.

0
 
LVL 18

Accepted Solution

by:
deighton earned 70 total points
Comment Utility
After you import your file, run an update query, something like below. 2002 represents the latest year you can be born in.  If you have no children in your table, then you might want to change that to 1990 (for example)


UPDATE birthdates SET birthdates.dob = DateAdd("yyyy",-100,[dob])
WHERE Year([dob]) > 2002;



this finds dates that have converted to 2030 (say) and corrects them to 1930.
0
 

Author Comment

by:Easty
Comment Utility
i am using access 2000.

changing the input file isn't really an option

The data is first imported into a table in access, then a  make table query is currently run on the data, this is the stage at which the dates are changed.

Is there any formatting you can do on the CDate function to import 2000 dates as 1900.
I notice that if i import the text file into excel first the dates are correctly changed, but i would prefer to bypass this stage as it creates an extra step and i'd like to automate the process as much as possible.

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
<<i am using access 2000.>>

Ok.

<<changing the input file isn't really an option>>

Got it.

<<The data is first imported into a table in access, then a  make table query is currently run on the
data, this is the stage at which the dates are changed.

Is there any formatting you can do on the CDate function to import 2000 dates as 1900.
>>

  Sounds like your importing it as a text field.  If so that's good as you can run an update query to modify all the 2 digit dates <30 to 4 digits.  Then run your make table.


<<I notice that if i import the text file into excel first the dates are correctly changed, but i would
prefer to bypass this stage as it creates an extra step and i'd like to automate the process as much
as possible.>>

  You can do this in Access, but not witht he import wizard the way it is.  The rule for 2 digit years is that anything starting with 30 and up is assumed to be 2000, which you cannot change.  Excel is acting the opposite and assuming 1900.  Access used to be this way, but was changed with Access 97.  What are you guys doing in Excel with a birthdate of '01, which should be 2001 and not 1901?

Jim.
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
How about my earlier idea of a running a query to knock 100 off any dates greater than 2002

UPDATE birthdates SET birthdates.dob = DateAdd("yyyy",-100,[dob])
WHERE Year([dob]) > year(now);
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
deighton,

 That won't work.  He needs to know which dates are 2 digit vs 4 so he can determine which need to be reduced

For example, if he imports:

01
2001

He would get:
2001
2001

 and it should be:

1901
2001
0
 

Author Comment

by:Easty
Comment Utility
this seemed to be the best solution. Edited it slightly so it was in an if statement in the form of
iif([date of birth] >01/01/2002, dateadd("yyyy", -100, [date of birth]), [date of birth])

cheers.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now