Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2007

Tip: Looking for answers? Try searching our database.

Date function help needed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sophie - 31 Jan 2007 00:37 GMT
greetings to all

I need help with code for a function.  I'm getting close but keep messing
up.  My sports league determines the 'competing age' of its athletes, given
their DOB, as follows:

 If TODAY's date is from Jan 1 to Jun 30, then
   CompAge = the kid's age on Jan 1 of the CURRENT year.
 If TODAY's date is from Jul 1 to Dec 31, then
   CompAge = the kid's age on the FOLLOWING Jan 1.
Signature

Thanks
Sophie

Daniel - 31 Jan 2007 01:01 GMT
Do you need just years or do you need more of a breakdown year months days...

here are two good postings on the subject you should be able to get what you
need

http://groups.google.ca/group/comp.databases.ms-access/browse_thread/thread/4c02
f7b7b44727e4/d1a2c6cdb0b96309

http://groups.google.ca/group/microsoft.public.access.forms/browse_thread/thread
/e53c5420f5e32625/395a8cc421c6c2aa


Daniel

> greetings to all
>
[quoted text clipped - 6 lines]
>   If TODAY's date is from Jul 1 to Dec 31, then
>     CompAge = the kid's age on the FOLLOWING Jan 1.
raskew - 31 Jan 2007 06:01 GMT
Hi Sophie:

The following function will return Age in yy.mm.dd format:
************************************************************************************************************
Function fAge(dteStart As Variant, dteEnd As Variant) As Variant
'*******************************************
'Purpose:   Accurately return the difference
'           between two dates, expressed as
'           years.months.days
'Coded by:  raskew
'Inputs:    From debug (immediate) window
'           1) ? fAge(#12/1/1950#, #8/31/2006#)
'           2) ? fAge(#12/30/2005#, #1/2/2006#)
'Outputs:   1) 55.8.30
'           2) 0.0.3
'*******************************************

Dim intHold   As Integer
Dim dayhold   As Integer

  'correctly return number of whole months difference
  'the (Day(dteEnd) < Day(dteStart)) is a Boolean statement
  'that returns -1 if true, 0 if false
  intHold = DateDiff("m", dteStart, dteEnd) + (Day(dteEnd) < Day(dteStart))
 
  'correctly return number of days difference
  If Day(dteEnd) < Day(dteStart) Then
     dayhold = DateDiff("d", dteStart, DateSerial(year(dteStart), month
(dteStart) + 1, 0)) + Day(dteEnd)
  Else
     dayhold = Day(dteEnd) - Day(dteStart)
  End If
 
  fAge = LTrim(str(intHold \ 12)) & "." & LTrim(str(intHold Mod 12)) & "." &
LTrim(str(dayhold))

End Function
************************************************************************************************************

Call it like this to toggle between this year and next year, based on whether
the current month is >= July (7)

? fage(#12/1/1950#, dateserial(year(date())+ abs(month(date())>=7),1,1))
56.1.0

HTH - Bob

>greetings to all
>
[quoted text clipped - 6 lines]
>  If TODAY's date is from Jul 1 to Dec 31, then
>    CompAge = the kid's age on the FOLLOWING Jan 1.
raskew - 31 Jan 2007 11:38 GMT
Oops!

Last line should have read:

? fage(#12/1/1950#, dateserial(year(date())+ abs(month(date())>=7),1,0))

Sure wish we had an Edit feature in this forum

>Hi Sophie:
>
[quoted text clipped - 48 lines]
>>  If TODAY's date is from Jul 1 to Dec 31, then
>>    CompAge = the kid's age on the FOLLOWING Jan 1.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.