|
-
Jun 10th, 2006, 06:27 PM
#1
Thread Starter
New Member
Calculate age
What is the querry to show the age of a person (Year, Month, day) in any given date based on Birth date input.
-
Jun 10th, 2006, 06:34 PM
#2
PowerPoster
Re: Calculate age
Try searching...someone asked the same question recently
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jun 10th, 2006, 06:37 PM
#3
Thread Starter
New Member
Re: Calculate age
Thanks, do you know the query?
-
Jun 10th, 2006, 06:38 PM
#4
PowerPoster
Re: Calculate age
No, try searching...it was answered
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jun 10th, 2006, 08:16 PM
#5
Re: Calculate age
Here is the code:
VB Code:
'A function which accepts date of birth from and returns age in exact years, months and days
Public Function ExactAge(BirthDate As Variant) As String
Dim yer As Integer, mon As Integer, d As Integer
Dim dt As Date
Dim sAns As String
If Not IsDate(BirthDate) Then Exit Function
dt = CDate(BirthDate)
If dt > Now Then Exit Function
yer = Year(dt)
mon = Month(dt)
d = Day(dt)
yer = Year(Date) - yer
mon = Month(Date) - mon
d = Day(Date) - d
If Sgn(d) = -1 Then
d = 30 - Abs(d)
mon = mon - 1
End If
If Sgn(mon) = -1 Then
mon = 12 - Abs(mon)
yer = yer - 1
End If
sAns = yer & " year(s) " & mon & " month(s) " & d & " day(s) old."
ExactAge = sAns
End Function
-
Jun 11th, 2006, 05:03 AM
#6
-
Jun 13th, 2006, 11:30 AM
#7
Thread Starter
New Member
Re: Calculate age
sorry I am new with this forum, I shall do it
-
Jun 13th, 2006, 11:39 AM
#8
Re: Calculate Age
You would use any of the date functions like DateDiff for example.
What Office App are you using?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 11:51 AM
#9
Thread Starter
New Member
Re: Calculate Age
I am using Access2000, try it DateDiff does not work.
Say someone is born in May 10, 2000, I want the query to tell me 6 y, 1m, 3 d
-
Jun 13th, 2006, 12:02 PM
#10
Re: Calculate Age
Yes, it works but you need to build your format if you want it like that. Pass one call for the years and then another for the months from birth month to current date then again for days, etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 12:06 PM
#11
Thread Starter
New Member
Re: Calculate Age
Could you post an example I am not sure if I understand what you mean by [Pass one call]
-
Jun 13th, 2006, 01:12 PM
#12
Re: Calculate Age
VB Code:
Function GetAge(BirthDate As Date) As String
Dim dNow As Date
Dim lTemp As Long
Dim sTemp As String
dNow = Now()
'---------------------------------------
' Year Part
'---------------------------------------
lTemp = DateDiff("yyyy", BirthDate, dNow)
If lTemp = 1 Then
sTemp = CStr(lTemp) & " Year, "
Else
sTemp = CStr(lTemp) & " Years, "
End If
BirthDate = DateAdd("yyyy", lTemp, BirthDate)
'---------------------------------------
' Month Part
'---------------------------------------
lTemp = DateDiff("m", BirthDate, dNow)
If lTemp = 1 Then
sTemp = sTemp & CStr(lTemp) & " Month, "
Else
sTemp = sTemp & CStr(lTemp) & " Months, "
End If
BirthDate = DateAdd("m", lTemp, BirthDate)
'---------------------------------------
' Day Part
'---------------------------------------
lTemp = DateDiff("d", BirthDate, dNow)
If lTemp = 1 Then
sTemp = sTemp & CStr(lTemp) & " Day"
Else
sTemp = sTemp & CStr(lTemp) & " Days"
End If
'---------------------------------------
' Output
'---------------------------------------
GetAge = sTemp
End Function
Last edited by DKenny; Jun 13th, 2006 at 01:16 PM.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 13th, 2006, 01:34 PM
#13
Thread Starter
New Member
Re: Calculate Age
thank you very much I will try it
-
Jun 13th, 2006, 01:44 PM
#14
Re: Calculate Age
Just something like this...
VB Code:
Dim sAge As String
sAge = DateDiff("yyyy", "5/10/2000", Date) & " years"
MsgBox sAge
Edit: Should have refreshed. 
Note: It will return only the years and not partials.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 01:52 PM
#15
Thread Starter
New Member
Re: Calculate Age
The date field is available from the list of individuales that are in the database and we do not want to enter their date of birth eveytime we want to see their age.
-
Jun 13th, 2006, 02:31 PM
#16
Re: Calculate Age
OK, so just add this custom function to the DB and then call it in a query, passing the DOB of the current record.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|