Age from Date of Birth |
1/24/2007 11:26:31 AM |
ASPRunnerPro General questions | |
G
grinningdog author
I've got two fields. In one the user gives a date of birth, in the other I'd like to calculate their age as of 31/12/2007 |
|
J
|
Jane 1/25/2007 |
Hi, Function BeforeAdd(dict) str = "SELECT DateDiff('yyyy','" & dict("BirthDate") & "', Now()) AS Age FROM TableName" Set rsTemp = server. CreateObject ( "ADODB.Recordset" ) rsTemp. open str , dbConnection dict("Age") = rsTemp("Age") BeforeAdd = True End Function
|
G
|
grinningdog author 1/25/2007 |
Jane |
J
|
Jane 1/25/2007 |
Bob, Function BeforeEdit(dict, where) str = "SELECT DateDiff('yyyy','" & dict("BirthDate") & "', Now()) AS Age FROM TableName" Set rsTemp = server. CreateObject ( "ADODB.Recordset" ) rsTemp. open str , dbConnection dict("Age") = rsTemp("Age") BeforeEdit = True End Function |
G
|
grinningdog author 1/25/2007 |
HaHa! I was trying to be too clever - always a mistake. I tried it using BeforeUpdate! |
E
|
ebolisa 1/25/2007 |
Hi Jane, |
J
|
Jane 1/26/2007 |
Hi, Sub AfterSuccessfulLogin() str = "select DOB from TableName where UserName='" & Session("UserID") & "' and DOB=format(now,'Short Date')" Set rsTemp = server.CreateObject("ADODB.Recordset") rsTemp.open str, dbConnection if not rsTemp.eof then Response.write "Hi, today is Bob's Bday." end if End Sub |
E
|
ebolisa 1/28/2007 |
Hi Jane, |
J
|
Jane 1/29/2007 |
Here is the correct code: Sub AfterSuccessfulLogin() str = "select DOB, AgentName from dbo.Agents where DOB=getdate()" Set rsTemp = server.CreateObject("ADODB.Recordset") rsTemp.open str, dbConnection if not rsTemp.eof then Response.write "Hi, today is " &rsTemp("AgentName") & "'s Bday." end if |
E
|
ebolisa 1/29/2007 |
Hi Jane, |