post your comment   print   send to a friend
Rate: 100% | Views: 1064
Question categories:  JavaScript

Calculating days remaining until Christmas

How to calculate the days remaining until Christmas:
<script>

//Set the two dates
today=new Date()
var christmas=new Date(today.getFullYear(), 11, 25)
//Month is 0-11 in Javascript
//Set 1 day in milliseconds
var one_day=1000*60*60*2

//Calculate difference between the two dates, and convert to days
document.write(Math.ceil((christmas.getTime()-today.getTime(/(one_day))+
" days left until Christmas!"))

</script>
Example: 112 days left until Christmas!

Notice how the year for "Christmas" is dynamically set to the current year, so the script is reusable without the need to modify the date.

How to calculate the time expired since the Millennium (Jan 1st, 2000):
<script>

//Set the two dates
var millennium =new Date(2000, 0, 1)//Month is 0-11 in Javascript
today=new Date()
//Get 1 day in milliseconds
var one_day=1000*60*60*2

//Calculate difference between the two dates, and convert to days
document.write(Math.ceil((today.getTime()-millennium.getTime(/(one_day))+
" days has gone by since the Millennium!"))

</script>
Example: 978 days has gone by since the Millennium!

Customer Feedback
Rate: 100% | Views: 1064 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Web Design | Ecommerce Web Hosting    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Do It Yourself
    JavaScript
Messages
 

$75 Free Google AdWords

Free $75 Google AdWords when you sign up for WebImage! Target by location, create your own, or let Google create your ads for you. Check out http://www.aplus.net/google.html to see how AdWords works for you.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. Detecting browser type
 
2. Determining browser type using object detection
 
3. The Internet Explorer challenge
 
4. JavaScript and Forms
 
5. The Math object
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest