By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Date Funtion (month)

P: n/a
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Rather than having 2 field which contain virtually the same information, it
would probably be better to get the year using a query from your DOB field.
Something like: YOB: DatePart("yyyy",[DOB])

Mark
"Paolo" <jp***@tin.it> wrote in message
news:9f**************************@posting.google.c om...
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.

Nov 13 '05 #2

P: n/a
Paolo wrote:
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.


Year(DOB) As YOB

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Nov 13 '05 #3

P: n/a
By writing Year(DOB) you can extract the year from a date! If you used
DAO you could automatically fill the table

Dim MyDb As Database
Dim MyRecs As DAO.Recordset
Set MyDb = CurrentDb()
Set MyRecs = MyDb.OpenRecordset("YourTableName", DB_OPEN_DYNASET)

MyRecs.MoveLast
MyRecs.MoveFirst 'this loads up your table and allows you the
count
' the records

For i = 1 to MyRecs.RecordCount
MyRecs.Edit
MyRecs!YOB = Year(MyRecs!DOB)
MyRecs.Update
MyRecs.MoveNext

Next

You have to go to tools, references and activate the DAO 3.6 Library
jp***@tin.it (Paolo) wrote in message news:<9f**************************@posting.google. com>...
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.

Nov 13 '05 #4

P: n/a
Ian
jp***@tin.it (Paolo) wrote in message news:<9f**************************@posting.google. com>...
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.


Since YOB will be a derived or calculated field this probably wouldn't
be wise (unless you doing this to speed up data retrieval). It would
be better displayed as a calculated or formatted control on a form.
There are two functions you could use to calculate this: DatePart and
Format.

DatePart("yyyy",[DOB]) - returns a numeric
Format([DOB],"yyyy") - returns a string

The easiest way would be to create a control with Control Source = DOB
and Format property to "yyyy".
Nov 13 '05 #5

P: n/a
Sure, you can do that, but why would you want to? Simply create a query with
a computed field in it, and use the query wherever you would otherwise have
used the table. It's actually a violation of relational database theory to
store a field which is totally dependent on other fields in the same row.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MissiMaths" <mi********@hotmail.com> wrote in message
news:75**************************@posting.google.c om...
By writing Year(DOB) you can extract the year from a date! If you used
DAO you could automatically fill the table

Dim MyDb As Database
Dim MyRecs As DAO.Recordset
Set MyDb = CurrentDb()
Set MyRecs = MyDb.OpenRecordset("YourTableName", DB_OPEN_DYNASET)

MyRecs.MoveLast
MyRecs.MoveFirst 'this loads up your table and allows you the
count
' the records

For i = 1 to MyRecs.RecordCount
MyRecs.Edit
MyRecs!YOB = Year(MyRecs!DOB)
MyRecs.Update
MyRecs.MoveNext

Next

You have to go to tools, references and activate the DAO 3.6 Library
jp***@tin.it (Paolo) wrote in message

news:<9f**************************@posting.google. com>...
Hello,
I have a field used to add date of births, named DOB.

I would like to add another field, named it YOB, which automatically
returns the year of birth from the previous field. Any help? Thanks.

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.