PDA

View Full Version : Code to check date then do action



mikkiburns
10-26-2005, 07:11 PM
I'm building an advent calendar and am not au fait with flash. I need code that will check date (PC set date will do) then perform set action depending on date. Anyone any ideas? I'll post this in dhtml too.
many thanks
M
:confused:

jscheuer1
10-27-2005, 06:14 AM
Here is a very simple javascript along the lines of what you propose:


<script type="text/javascript">
var someDate=new Date()
if(someDate.getMonth()+1==12&&someDate.getDate()==25){
alert('Merry Christmas!')
}
</script>

In place of the red line, you can have a more elaborate line(s) to perform more elaborate actions.

In the first green line, the red numbers check for the month (12 for December) and date (25 for the 25th). You can have as many of these tests and subsequent actions as needed and it will probably be desirable to have the code be a function activated onload:


<script type="text/javascript">
function advent(){
var someDate=new Date()
if(someDate.getMonth()+1==12&&someDate.getDate()==25){
code for Christmas Day goes here
}
if(someDate.getMonth()+1==12&&someDate.getDate()==24){
code for Christmas Eve goes here
}
if(someDate.getMonth()+1==12&&someDate.getDate()==18){
code for something on December 18th could go here
}
}

onload=advent;
</script>

mikkiburns
10-30-2005, 10:19 AM
That's REALLY helpful - many many thanks! And I should say - i am NOT a student as profile suggests but a teacher! and a very busy one at that so I am VERy grateful!