dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java, Web
Expertise: Beginner
Aug 31, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Days Left Until Specific Date

Using the Date functionality in JavaScript, you can post the number of days left until a certain date. Internally, JavaScript stores dates as the number of milliseconds from midnight (GMT) on January 1, 1970. If you subtract two Date objects, the result is the number of milliseconds between the two dates. The following code sample subtracts the future (target) date from today's date (returned by Date() with no arguments) and then multiplies to convert milliseconds into days.
 
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

function datediff(target) {
   // target must in the format
   'Month Day, Year' like 'July 4,
   2000'

   var today = new Date();
   var tomorrow = new Date(target);
   var diff;

   diff = tomorrow - today; // number
 of milliseconds between the two
 dates
   diff = parseInt(diff / (1000 * 60
 * 60 * 24)); // convert to days and
 round off

   document.write(diff);
}

</SCRIPT>
</HEAD>
<BODY>

There are only <SCRIPT
LANGUAGE="JavaScript">datediff('July
4, 2000');</SCRIPT> days left until
liftoff.

</BODY>
</HTML>

Boris Feldman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date