|
Web Page How-To - Date Comparision
This example will display an image if a number of days hasn't passed.If more than x number of days have passed then no image will appear.
Defines:
Limit is the number of days to show the image.
Today is today's date in number of milliseconds, since Jan 01, 1970.
Dte is the date passed into the function. This is the date you are comparing to.
NDte is Dte converted into number of milliseconds since Jan 01, 1970.
Dff is the number of days between today and Dte.
864e5 is the number of milliseconds in one day.
(60sec * 60min * 24hrs = 864000sec_per_day = 643e5millisec_per_day)
How it Works:
Today's date is first saved to the variable 'today'. Dte is then converted into the number of milliseconds that has passed since Jan 01, 1970 and saved to the variable 'NDte'. The difference between 'today' and 'NDte' is then divided by the number of milliseconds in one day, this result is saved to the variable 'Dff' as the number of days between today's date and the comparision date. If 'Dff' is less than or equal to 'Limit' then the document will display the image, else it will end doing nothing.
Insert this in the webpage head
<SCRIPT>
function CheckDat(Dte){
limit = 30
today = new Date()
NDte = new Date(Date.parse(Dte))
Dte = (today = NDte)/864e5
if (Dff <= Limit) {
document.writeln ("<img SRC=\"path_of_image" NOSAVE HEIGHT=10 WIDTH=10 >")
}
}
</SCRIPT>
Insert this where you want the image to appear in the webpage body:
<SCRIPT>
CheckDat("11/01/2004")
</SCRIPT>
|