Compare Dates

[Total: 0    Average: 0/5]

This shows how to calculate the number of days from March, 16, 2000 to today.

Body Code:

<script type=text/javascript>
var _m = "2" // march
var _d = "16"
var _y1 = "2000"
var _d2 = new Date() // current date
var _d1 = new Date()
    _d1.setMonth(_m)
	_d1.setDate(_d)
	_d1.setYear(_y1)
function DaysDelta(_v1,_v2) {
  var _delta = 0;
  var _a1 = _v1;
  var _a2 = _v2;
  if (_v1.getTime() < _v2.getTime()) {
    _a1 = _v2;
	_a2 = _v1;
  }
  _delta = _a1.getTime() - _a2.getTime(); // in msecs
  _delta /= (1000 * 60 * 60 * 24); // days
  return _delta;
}
document.write("Date 1 = "+_m+"/"+_d+"/"+_y1+"<BR>")
document.write("Date 2 = "+_d2.getMonth()+"/"+_d2.getDate()+"/"+_d2.getYear()+"")
var _X = 4.5 // in thousands!
var _d = DaysDelta(_d1,_d2);
var _v = _d * _X * 1000
document.write('<BR>Delta Days = '+_d);
document.write('<BR><BR>New Value='+_v);
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *