|
February 19, 2001 Forward-Computing the Date Tips: February 2001
Yehuda Shiran, Ph.D.
|
|
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:
Click here to try it.
People who read this tip also read these tips: Look for similar tips by subject: |
| ||||||||||||||||||||