Three fields to represent a date?

J

Jennifer K.

I am creating a table that needs to have the date (i.e. 01/31/2008) stored as
three separate fields as follows to be consistent with an older database.

Month, length of 2 and can have 01-12 or 99 for unknown month (i.e. 01).
Day, with a length of 2 and can have 01-31 or 99 for unknown day (i.e. 31).
Year, with a lenght of 4 or 9999 for unknown year (i.e. 2008).

Can these be recognized as dates (or components of dates) in an Access
table? Can there be 9's for unknowns and still be a date or recognize the
known date components.
If they cannot be dates then they should just be formatted as numbers?

Thanks,
Jennifer
 
D

Danny Seager

format the fields as numbers.. you can "make them a date" in a query using
the DateSerial() function
 
J

John W. Vinson

I am creating a table that needs to have the date (i.e. 01/31/2008) stored as
three separate fields as follows to be consistent with an older database.

Month, length of 2 and can have 01-12 or 99 for unknown month (i.e. 01).
Day, with a length of 2 and can have 01-31 or 99 for unknown day (i.e. 31).
Year, with a lenght of 4 or 9999 for unknown year (i.e. 2008).

Can these be recognized as dates (or components of dates) in an Access
table? Can there be 9's for unknowns and still be a date or recognize the
known date components.
If they cannot be dates then they should just be formatted as numbers?

Well, they certainly cannot be date/time fields; and they certainly should not
be named using the reserved words Month, Day and Year. Consider using
Number/Long Integer fields with other names (I'll use TheMonth, TheDay,
TheYear below). Could you explain why it "needs" to be stored in this manner?
It might have been necessary to do so with your older software but it
certainly isn't now! You can use the DateSerial() function to construct a
date, using IIF() to detect the 99's:

IIF([TheDay] = 99 Or [TheMonth] = 99 Or [TheYear] = 9999, Null,
DateSerial([TheYear], [TheMonth], [TheDay]))

will return NULL for a partially unknown date and the actual date otherwise.
 
J

Jennifer K.

Thank you both for your input and it follows what I had been planning to do.
It was extremely helpful. I advocated for storing the date as a date
but...change is hard.
Thank you again,
Jennifer

John W. Vinson said:
I am creating a table that needs to have the date (i.e. 01/31/2008) stored as
three separate fields as follows to be consistent with an older database.

Month, length of 2 and can have 01-12 or 99 for unknown month (i.e. 01).
Day, with a length of 2 and can have 01-31 or 99 for unknown day (i.e. 31).
Year, with a lenght of 4 or 9999 for unknown year (i.e. 2008).

Can these be recognized as dates (or components of dates) in an Access
table? Can there be 9's for unknowns and still be a date or recognize the
known date components.
If they cannot be dates then they should just be formatted as numbers?

Well, they certainly cannot be date/time fields; and they certainly should not
be named using the reserved words Month, Day and Year. Consider using
Number/Long Integer fields with other names (I'll use TheMonth, TheDay,
TheYear below). Could you explain why it "needs" to be stored in this manner?
It might have been necessary to do so with your older software but it
certainly isn't now! You can use the DateSerial() function to construct a
date, using IIF() to detect the 99's:

IIF([TheDay] = 99 Or [TheMonth] = 99 Or [TheYear] = 9999, Null,
DateSerial([TheYear], [TheMonth], [TheDay]))

will return NULL for a partially unknown date and the actual date otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Changing Date Format? 4
Criteria Query Error Please Help 4
adding three fields with time values 1
Date Diff Issue 4
Date Serial Problem 2
Dlookup 7
Excel Vba to change displayed year automatically. 14
format date in table 3

Top