<script type="text/javascript">
if (top!= self) top.location.href = self.location.href;
function days_between(date1, date2) {
// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24;
// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
// Calculate the difference in milliseconds
var difference_ms = Math.abs(date1_ms - date2_ms);
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY);
};
check_date(date1) {
var now = new Date();
if ((days_between(date1, now) < 1)
document.write("expired");
else
document.write(days_between(date1, now), " days remaining");
};
I invoke it with a script segment inside a table cell
tags, which have an {Expand] button. superdesign has already given you instructions, though. For future reference, when you're posting code here, try to use the appropriate code tags to make your posts as readable as possible.]
Last edited by califdon on Sun Apr 24, 2011 7:52 pm, edited 2 times in total.
Reason:I realized that I had overlooked your second "function" definition.
function days_between(date1, date2) {
// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24;
// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
// Calculate the difference in milliseconds
var difference_ms = Math.abs(date1_ms - date2_ms);
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY);
};
function check_date(date1) {
var now = new Date();
if ((days_between(date1, now) < 1)
document.write("expired");
else
document.write(days_between(date1, now), " days remaining");
return;
};