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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint