Number of Weeks Until...

# Thread: Number of Weeks Until...

1. Senior Member
Join Date
Dec 1969
Posts
167

## Number of Weeks Until...

Hi! I&#039;ve read the FAQs that deal with dates and have come up with the following code:<BR><BR>&#039;Use DateSerial() to avoid location issues<BR> Dim dteUser, dteCurrent<BR> dteUser = DateSerial(qryBirthYear, qryBirthMonth, qryBirthDay) <BR> dteCurrent = DateSerial(year(date), month(date), day(date)) <BR> <BR> &#039;Do we have a valid date? <BR> If dteCurrent &#062;= dteUser Then <BR> <BR> &#039;Get absolute number of years.<BR> Dim intAgeInYears<BR> intAgeInYears = CInt(datediff("yyyy", dteUser, dteCurrent)) <BR> <BR> &#039;Get User&#039;s month and day in terms of the current year.<BR> Dim dteUseralt<BR> dteUseralt = dateadd("yyyy", intAgeInYears, dteUser) <BR> <BR> If dteUseralt &#062; dteCurrent Then <BR> &#039;Their birthday hasn&#039;t passed yet this year. <BR> intAgeInYears = intAgeInYears - 1 <BR> End If <BR> <BR> Response.Write "Age: " & intAgeInYears & "<BR><BR>"<BR> <BR> Else<BR> <BR> Response.Write "You&#039;ve given me an invalid date!"<BR> <BR> End If<BR> <BR>------------------------<BR>That code determines the number of years old the user is and then prints it out.<BR><BR>My next step is to determine how many weeks until they are 13 if they aren&#039;t already 13.<BR><BR>I know I really should be able to come up with the code, but I&#039;m drawing a blank. Can anyone help?<BR><BR>Thanks,<BR><BR>Defiant005

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

thirteen = DateAdd( "y", 13, birthDate )<BR>weeksuntil = DateDiff( "w", Date(), thirteen )<BR>If weeksuntil &#060; 0 Then<BR> Response.Write "Congratulations, you are already 13 years old."<BR>Else<BR> Response.Write "You have to wait " & weeksuntil & " weeks."<BR>End If<BR><BR>*********<BR><BR>Why are you doing *this*:<BR> dteCurrent = DateSerial(year(date), month(date), day(date)) <BR>That will end up giving you the same thing you get from--what else?--<BR> dteCurrent = Date<BR><BR>In point of fact, putting in dteCurrent is 100% useless.<BR><BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
167

## Ah, I see! Thanks and...

Hi Bill,<BR><BR>Thanks for your quick response!<BR><BR>I just want to double check, but did you happen to mean:<BR><BR>thirteen = DateAdd("yyyy", 13, birthDate)<BR><BR>It doesn&#039;t seem to work quite right with "y".<BR><BR>About why I was doing dteCurrent = ..., I&#039;m not exactly sure. I guess my mind was set in the whole DateSerial thing so I just went ahead and wrote it like that. :-)<BR><BR>Thanks again!<BR><BR>Defiant005<BR><BR>P.S. http://msdn.microsoft.com/library/en-us/script56/html/vsfctDateAdd.asp?frame=true

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

## Yes, brain fart...

...forgot about diff between "yyyy" and "y" for that function.<BR><BR>Ehhh...see, you didn&#039;t need my answer; you had the docs.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
167

## So We're Even?

Heck yes I do! It&#039;s one of the first in line on my "Favorites" menu!<BR><BR>You had a brain fart about "yyyy" and I had one about the entire code...Would you call that even? LOL<BR><BR>Thanks again,<BR><BR>Defiant005

#### Posting Permissions

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