Just can't figure this out

# Thread: Just can't figure this out

1. Senior Member
Join Date
Dec 1969
Posts
370

## Just can't figure this out

I have a script that calculates the age (or at least it&#039;s supposed to). Problem is, it&#039;s not taking the month into consideration. For example, if your b-day is 12/31/70 it will tell me you&#039;re 32, instead of 31. Here it is, I can&#039;t think too straight I guess. I&#039;m sure it&#039;s something simple.<BR><BR>strage = strage & objrs("M_YEAR")<BR>DiffADATE= DateDiff("yyyy", strage, Now)

2. Senior Member
Join Date
Dec 1969
Posts
96,118

...on DateDiff. You will find that for diff between two years, it *does* ignore the month and day (and hour and minute and second). Same way diff between two months ignores day (et al.). Etc.<BR><BR>SO:<BR><BR>&#060;%<BR>birthdate = CDate( ... )<BR>years = Year(Date()) - Year(birthdate)<BR>If ( ( Month(Date()) &#060; Month(birthdate) ) _<BR> OR ( Month(Date()) = Month(birthdate) AND Day(Date()) &#060; Day(birthdate) ) _<BR> ) Then<BR> years = years - 1<BR>End If<BR>%&#062;<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
370

Thanks a bunch. I&#039;m also going to read the documentation a little closer

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Here's what I meant:

From this page:<BR>http://msdn.microsoft.com/library/en-us/script56/html/vsfctdatediff.asp<BR><BR>*** QUOTE ***<BR>When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("yyyy") returns 1 even though only a day has elapsed.<BR>*** END QUOTE ***<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
370

## One more thing

Ok, I must be very brain dead. My fields are M_MONTH, M_DAY AND M_YEAR. I&#039;m having difficulty with what you sent. Understand, I&#039;m a bit under the whether, but have to finish this b4 the evening ends. Understandable if you feel as if you&#039;re writing code and don&#039;t want to but....:)

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Fields from what?

Have you already validated them, to be sure they contain a legal date?<BR><BR>If not, you could do this:<BR>&#060;% <BR>[hl="yellow"]birthdate = DateSerial( M_YEAR, M_MONTH, M_DAY )[/hl]<BR>%&#062;<BR>and then the rest of the code stays the same.<BR><BR>**********<BR><BR>If you are sure they are valid numbers for a valid date, then just don&#039;t bother with the "birthdate" variable and substitute them for the "extracted" values:<BR><BR>&#060;%<BR>years = Year(Date()) - M_YEAR<BR>If ( ( Month(Date()) &#060; M_MONTH ) _ <BR> OR ( Month(Date()) = M_MONTH AND Day(Date()) &#060; M_DAY ) _ <BR> ) Then <BR> years = years - 1 <BR>End If <BR>%&#062; <BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•