
Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
>> I have a large database where the Date of birth has been set to type
>> integer of the form dd/mm/yy.
[quoted text clipped - 18 lines]
>
> 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))

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
John W. Vinson - 29 May 2007 21:22 GMT
>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
[quoted text clipped - 4 lines]
>Mid(CStr([DOB]), 5, 2)), CLng("20" & Mid(CStr([DOB]), 5, 2))),
>CLng(Mid(CStr([DOB]), 3, 2)), CLng(Mid(CStr([DOB]), 1, 2))
I was curious so I checked: I knew DateSerial was a clever bit of code, but
it's even cleverer than I thought!
?dateserial(7,5,29)
5/29/2007
?dateserial(29,1,1)
1/1/2029
?dateserial(30,1,1)
1/1/1930
so it uses the familiar two/four digit convention.
Dates of birth *really* need to be four digit. There are lots of centenarians
around now, and being born in '05 (or even in '98) is still ambiguous!
John W. Vinson [MVP]
Douglas J. Steele - 29 May 2007 21:44 GMT
>>Far safer is to use the DateSerial function. However, that does require a
>>4
[quoted text clipped - 20 lines]
>
> so it uses the familiar two/four digit convention.
Actually, it makes sense that it would use whatever's defined on the Date
tab under Customer Regional Options for the "When a two-digit year is
entered, interpret it as a year between",
> Dates of birth *really* need to be four digit. There are lots of
> centenarians
> around now, and being born in '05 (or even in '98) is still ambiguous!
No argument from me on this point!

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
Dirk Goldgar - 29 May 2007 22:04 GMT
> 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).
Good point, Doug. I forgot that CDate would use the regional settings.
I was thinking it was like Jet's interpretation of date literals.

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)