Welcome to Dream.In.Code
Become an Expert!

Join 149,875 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,303 people online right now. Registration is fast and FREE... Join Now!




Graduation Date Calculator

 
Reply to this topicStart new topic

Graduation Date Calculator

Speechist
18 Mar, 2005 - 09:28 AM
Post #1

D.I.C Head
Group Icon

Joined: 2 Dec, 2004
Posts: 86



Thanked: 1 times
Dream Kudos: 50
My Contributions
I'm looking for a straight-forward, self-contained JS that takes a date (someone's birthdate in mm/dd/yyyy format) and calculates the YEAR when that person will turn 18. I'm integrating the script into a PDF form using fields so it's not web-based. Most of the scripts available are htm-form based and that's not what I need.

I've tried some basic JS that takes a variable's value and performs a simple addition action but I'm not getting what I'm after. It has to be a JavaScript.

Thanks in advance! cool.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Graduation Date Calculator
18 Mar, 2005 - 10:09 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
CODE

<script language="javascript">
var reply = prompt("Please enter your date of birth (mm/dd/yyyy)", " ");
var newstring = new String(reply);
var arrTemp = new Array();
arrTemp = newstring.split("/");
var year = parseInt(arrTemp[arrTemp.length-1]);
year += 18;
alert("You were born in " + parseInt(arrTemp[arrTemp.length-1]) + "\nYou will graduate in the year of our Lord " + year);
</script>

As an FYI, you could also use the javascript Date object, but it didn't seem necessary. Please note that this does not validate user input...it is always wise to validate.
User is online!Profile CardPM
+Quote Post

Speechist
RE: Graduation Date Calculator
18 Mar, 2005 - 10:17 PM
Post #3

D.I.C Head
Group Icon

Joined: 2 Dec, 2004
Posts: 86



Thanked: 1 times
Dream Kudos: 50
My Contributions
Thanks Amadeus,

I'll give this a try when I get back to the office. cool.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:47AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month