Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


DOB to your Age

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2644
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> DOB to your Age
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 DOB to your Age - 4/11/2005 6:59:02 AM   
  hottnicks4201

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
I have to do a project that takes your date of birth and converts it into your age. im farely new with vbscript so if someone can help i could greatly appreciate thank you.
 
 
Post #: 1
 
 Re: DOB to your Age - 4/11/2005 7:15:46 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Quite simple,

WScript.Echo cdate(Date - #MM/DD/YYYY#)

will produce your age PLUS 1900 year. So if you subtract 1900 from the YYYY, you will get the exact age, X years, Y months, and Z days old

=)

(in reply to hottnicks4201)
 
 
Post #: 2
 
 Re: DOB to your Age - 4/11/2005 7:18:54 AM   
  hottnicks4201

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
i have to deal with leap years. this is basically my assignment.

Write a working VB script embedded in a HTML file that computes the age of a person when the date of birth is given as input (use one or three textboxes).

(in reply to hottnicks4201)
 
 
Post #: 3
 
 Re: DOB to your Age - 4/11/2005 7:22:58 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I believe it accounts for that, doesn't it ? Try it and let us know =)

(in reply to hottnicks4201)
 
 
Post #: 4
 
 Re: DOB to your Age - 4/11/2005 8:03:09 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
How would you type out the format of the Date var?

In Europe we use a different format then in the US..

(in reply to hottnicks4201)
 
 
Post #: 5
 
 Re: DOB to your Age - 4/11/2005 8:16:28 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
What do you mean by "How would you....... " ?

(in reply to hottnicks4201)
 
 
Post #: 6
 
 Re: DOB to your Age - 4/11/2005 11:41:31 AM   
  hottnicks4201

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
im really confused could somebody just show me from start to finish how i would be able to take the DOB to age in VBscript.

(in reply to hottnicks4201)
 
 
Post #: 7
 
 Re: DOB to your Age - 4/11/2005 3:06:38 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Enter your DOB in the line below, and

WScript.Echo cdate(Date - #MM/DD/YYYY#)

you should see a date printed out on your screen (eg:02/03/1944). You will then subtract 1900 from 1944 which equals to 44. That means, you are 44 years, 2 months, and 3 days old.

(in reply to hottnicks4201)
 
 
Post #: 8
 
 Re: DOB to your Age - 4/11/2005 9:39:50 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Here is an example based on what Token replied
      You'll probably still need to add some validation checking on the input, but it should get you started


HTH

(in reply to hottnicks4201)
 
 
Post #: 9
 
 Re: DOB to your Age - 4/12/2005 12:49:18 AM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
Zifter code was a great start, but the Day and Months were in reverse order, format should be MM/dd/yyyy also you need to subtract -1 from month also or you will be 1 month off.

<html>
<head>
<script language="VBScript">
Option Explicit
Function Calc()
Dim intDay
Dim intMonth
Dim intYear
Dim dttBirth
Dim dttDiff

intMonth = Document.frmDate.intMonth.value
intDay = Document.frmDate.intDay.value
intYear = Document.frmDate.intYear.value
dttBirth = CDate(intMonth & "/" & intDay & "/" & intYear)
dttToday = CDate(date)
dttDiff = CDate(Date - dttBirth)
MsgBox "You are " & Year(dttDiff)-1900 & " years, " & Month(dttDiff)-1 & _
" months and " & Day(dttDiff) & " days old"
End Function
</script>
</head>
<body>
<em> Enter your Date of Birth</em>
<form name=frmDate>
<input name=intMonth type=Text size=2 maxlength=2 /> /
<input name=intDay type=Text size=2 maxlength=2 /> /
<input name=intYear type=Text size=4 maxlength=4 /> (MM/DD/YYYY)
<p>
<input name=btnCalc type=Button value=Calculate onClick=Calc() />
</form>
</body>
</html>

(in reply to hottnicks4201)
 
 
Post #: 10
 
 Re: DOB to your Age - 4/12/2005 1:05:28 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Don't forget to add:
Dim dttToday

(in reply to hottnicks4201)
 
 
Post #: 11
 
 Re: DOB to your Age - 4/12/2005 1:27:55 AM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
Thanks Country,
Actually just remove the following line it was jsut left over from my testing code.

dttToday = CDate(date)

(in reply to hottnicks4201)
 
 
Post #: 12
 
 Re: DOB to your Age - 4/12/2005 2:03:32 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
quote:
but the Day and Months were in reverse order, format should be MM/dd/yyyy

Date formats differ from country to country, so in case of the HTML inputfields, you can put them in any order that suits you (that is why I added "(DD/MM/YYYY)" behind the last inputfield)

In case of the CDate function, it depends on the Windows settings.
In some countries you'll need to enter the date in the format MM/DD/YYYY in other countries in the format DD/MM/YYYY, in again other countries ...
That is why I used dttBirth = CDate(intYear & "/" & intMonth & "/" & intDay), because I think this works independent of the Windows settings... I could be wrong ...


edit:Just found out there exists a function DateSerial(Year,Month,Day).
This function converts string or integers to a variant of subtype Date.
http://www.devguru.com/Technologies/vbscript/quickref/dateserial.html

(in reply to hottnicks4201)
 
 
Post #: 13
 
 Re: DOB to your Age - 4/12/2005 3:22:28 AM   
  hottnicks4201

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
Thank you for all that replied to my question. you helped me out so much. thanks again.

(in reply to hottnicks4201)
 
 
Post #: 14
 
 Re: DOB to your Age - 4/12/2005 6:57:50 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
No problem =)

heh, was that your assignment ?

(in reply to hottnicks4201)
 
 
Post #: 15
 
 Re: DOB to your Age - 4/13/2005 1:36:20 AM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
Zifter,
Thanks for that link, looks like it could be verry useful.

(in reply to hottnicks4201)
 
 
Post #: 16
 
 Re: DOB to your Age - 4/13/2005 2:45:16 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I can't understand why dateserial is useful, would someone shed some light ?

(in reply to hottnicks4201)
 
 
Post #: 17
 
 Re: DOB to your Age - 4/13/2005 7:40:30 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
thanks Zifter, as an European you hit the nail on the head...at least mine...lately i must do alotta scripting in MEL (for Alias Maya) so that got me confused for other "simple" VBScript functions.

I was indeed looking for the way you could push a "European" input to all this here....

-lol-

(in reply to hottnicks4201)
 
 
Post #: 18
 
 Re: DOB to your Age - 4/13/2005 7:43:52 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
quote:
Originally posted by token

I can't understand why dateserial is useful, would someone shed some light ?



Here's a lighter: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdateserial.asp

(in reply to hottnicks4201)
 
 
Post #: 19
 
 Re: DOB to your Age - 4/13/2005 8:12:22 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
heh.. Thanks. I know what it does; I just don't know why would anyone use that function ;P

oh well, I guess it WAS his school assignment after all ;) I don't like doing others homework :\

(in reply to hottnicks4201)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> DOB to your Age Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts