IIS ASP - Datetime field in VB script

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > April 2006 > Datetime field in VB script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Datetime field in VB script
tumb

2006-04-27, 7:52 am


Could someone show me an example to find the age of a person using VB
script if we know the birthdate.

Thanks in advance
M



--
tumb
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Stefan Berglund

2006-04-27, 7:52 am

On Thu, 20 Apr 2006 14:30:41 -0500, tumb <tumb.26l7hq@mail.codecomments.com> wrote:
in <tumb.26l7hq@mail.codecomments.com>

>
>Could someone show me an example to find the age of a person using VB
>script if we know the birthdate.
>
>Thanks in advance
>M


Here's some T SQL that does what you want. See if you can translate it.
It computes age as of a particular anniversary so just substitute the current
date for the anniversary date.

SET NOCOUNT ON
DECLARE @Anniversary SMALLDATETIME

SET @Anniversary =
CASE
WHEN MONTH(CURRENT_TIMESTAMP) = 12
THEN STR(YEAR(CURRENT_TIMESTAMP)) + '1201'
ELSE STR(YEAR(CURRENT_TIMESTAMP)-1) + '1201'
END

IF @Filter = 0
SELECT
E.FirstName AS [First Name],
E.LastName AS [Last Name],
E.Address1,
E.Address2,
CASE LEN(E.Zip) WHEN 6 THEN LEFT(E.Zip,3) + ' ' + RIGHT(E.Zip,3) ELSE E.Zip END AS Zip,
SUBSTRING(E.Phone1,1,3) + ' ' + SUBSTRING(E.Phone1,4,3) + ' ' + SUBSTRING(E.Phone1,7,4) AS Phone1,
SUBSTRING(E.Phone2,1,3) + ' ' + SUBSTRING(E.Phone2,4,3) + ' ' + SUBSTRING(E.Phone2,7,4) AS Phone2,
E.Email,
CASE E.Official WHEN 0 THEN '' ELSE 'Yes' END AS Official,
CASE Birthday
WHEN '1900-01-01'
THEN Age
ELSE LTRIM(STR(
CASE
WHEN DATEADD(year, DATEDIFF (year, Birthday, @Anniversary), Birthday) > @Anniversary
THEN DATEDIFF (year, Birthday, @Anniversary) - 1
ELSE DATEDIFF (year, Birthday, @Anniversary)
END))
END AS Age,
E.TaxID,
CASE Birthday WHEN 0 THEN '' ELSE CONVERT(VARCHAR(10),E.Birthday,111) END AS Birthday,

---
This posting is provided "AS IS" with no warranties and no guarantees either express or implied.

Stefan Berglund
Anthony Jones

2006-04-27, 7:52 am


"tumb" <tumb.26l7hq@mail.codecomments.com> wrote in message
news:tumb.26l7hq@mail.codecomments.com...
>
> Could someone show me an example to find the age of a person using VB
> script if we know the birthdate.
>
> Thanks in advance
> M
>
>
>
> --
> tumb
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>


You haven't specified the level or precision required.

Typically we are talking years hence we might be tempted with using the
DateDiff function

age = DateDiff("yyyy", datDOB, Now())

But this rounds to the nearest year which isn't typically what we want.

Distilling out Stefan's code to vbscript :-

age = DateDiff("yyyy", datDOB, Now())
If DateAdd("yyyy", age, datDOB) > Now() Then age = age - 1



Dave Anderson

2006-04-27, 7:52 am

tumb wrote:
> Could someone show me an example to find the age of a person
> using VB script if we know the birthdate.


You don't specify an aperture size, but this will give you the age in days:

DateDiff("d",BirthDate,Now)


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com