spacer
Yehuda Shiran February 19, 2001
Forward-Computing the Date
Tips: February 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

In many applications you need to forward-compute the date. As an example, a worker in a library with a 25-day return policy needs to know when a book is due. A pharmacist needs to compute the expiration date of a prescription drug with 63 day shelf period. A high school student wants to find out when his 28 day curfew ends, so he can start dating again. These are just a few examples where people need to forward compute the date. Luckily, JavaScript provides you with a wealth of Date methods. The trick is to create a Date object and to add the required number of days to its date property. Note that the number of days is expressed in milliseconds. Here is an example that demonstrates the library example above:

<SCRIPT LANGUAGE="JavaScript">
var now = new Date();
now.setTime(now.getTime() + 25 * 24 * 60 * 60 * 1000);
</SCRIPT>

Click here to try it.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business