matt 0


I was wondering if anyone knows of a javascript that will update content based on the date. For example, counting the days left of school, which is irregular, and might to be pre-programmed with an array. Any help, or suggestions would be greatly appreciated.


  • Why would you need an array to conditionally decrement a counter? Nathan Duran about 8 years ago

2 answers

This was chosen as the best answer

Maybe this will give you a push in the right direction, something small and silly I wrote a couple ofyears ago.

<script type="text/javascript"> 
var d = new Date()
var timeHour = d.getHours()
var strtime = ""

if (timeHour > 5)
strtime = "Good morning and"
if (timeHour > 11)
strtime = "Good afternoon and"
if (timeHour > 17)
strtime = "Good evening and"
if (timeHour > 19)
strtime = "It's getting late, but"
if (timeHour < 6)
strtime = "It's time to sleep, but still"
Answered about 8 years ago by Kyle Sevenoaks
  • several mistakes in this code: the brackets (at the start of the line) should be curly brackets "{" and "}". Lines should end in semi-colon ";". Document.write is non-standard and should be replaced by document.appendChild() or document.getElementById('mytime').innerHTML Michiel van der Blonk about 8 years ago

Using javascript & jQuery , you can do something like

var daymessages = ["2 days to go!","School finishes tomorrow"] var today=new Date() var school_is_finished=new Date(2010, 11, 25) var one_day=10006060*24 var days_to_go = Math.ceil((school_is_finished.getTime()-today.getTime())/(one_day))

// set the message in the html $('#contentarea').html(daymessages[days_to_go])

Answered about 8 years ago by macarthy