Dirk Goldgar said:
In
Ajrbruce said:
I have a large database where the Date of birth has been set to type
integer of the form dd/mm/yy.
Integer? Not Long Integer? An Integer field in Access/Jet can't hold
6-digit numbers. Unless this database is in some other file format, I'm
going to assume you mean Long Integer.
I need to perform some calculations on
the dates but when I try to just change the type to date it seems to
come up with a totally different date.
Can anyone suggest how these can be converted and still keep the
correct values?
Do you mean that today's date, for example, would be stored as 290507? If
so, you might try an expression like
CDate(Mid(CStr([DOB]), 3, 2) & "/" &
Mid(CStr([DOB]), 1, 2) & "/" &
Mid(CStr([DOB]), 5, 2))
where DOB is the name of the field.
Since the OP is wanting to use dd/mm/yy, odds are that's the Short Date
format on the machine (as set through Regional Settings).
That means that while
CDate(Mid(CStr([DOB]), 3, 2) & "/" &
Mid(CStr([DOB]), 1, 2) & "/" &
Mid(CStr([DOB]), 5, 2))
will work fine for a value of 290507 for DOB, it will result in 06 Jan,
2007, not 01 Jun, 2007, when the value for DOB is 010607.
Far safer is to use the DateSerial function. However, that does require a 4
digit year, so some logic will have to be used to determine whether the year
should be in the 1900s or the 2000s. If we're dealing with DOB, it's likely
legimate to use:
DateSerial(IIf(Mid(CStr([DOB]), 5, 2) > CStr(Year(Date())), CLng("19" &
Mid(CStr([DOB]), 5, 2)), CLng("20" & Mid(CStr([DOB]), 5, 2))),
CLng(Mid(CStr([DOB]), 3, 2)), CLng(Mid(CStr([DOB]), 1, 2))