|
I figured it out already. Thanks anyway.
Basically I wanted a number on a page that counted up by x per day. Kinda like a Hamburgers sold since 1966 type of thing.
Here is the code. It if far more advanced than what I needed, and allows for more variables. But I used the D section.
<script language="javascript"> function suycDateDiff( start, end, interval, rounding ) {
var iOut = 0; // Create 2 error messages, 1 for each argument. var startMsg = "Check the Start Date and End Date\n" startMsg += "must be a valid date format.\n\n" startMsg += "Please try again." ; var intervalMsg = "Sorry the dateAdd function only accepts\n" intervalMsg += "d, h, m OR s intervals.\n\n" intervalMsg += "Please try again." ;
var bufferA = Date.parse( start ) ; var bufferB = Date.parse( end ) ; // check that the start parameter is a valid Date. if ( isNaN (bufferA) || isNaN (bufferB) ) { alert( startMsg ) ; return null ; } // check that an interval parameter was not numeric. if ( interval.charAt == 'undefined' ) { // the user specified an incorrect interval, handle the error. alert( intervalMsg ) ; return null ; } var number = bufferB-bufferA ; // what kind of add to do? switch (interval.charAt(0)) { case 'd': case 'D': iOut = parseInt(number / 86400000) ; if(rounding) iOut += parseInt((number % 86400000)/43200001) ; break ; case 'h': case 'H': iOut = parseInt(number / 3600000 ) ; if(rounding) iOut += parseInt((number % 3600000)/1800001) ; break ; case 'm': case 'M': iOut = parseInt(number / 60000 ) ; if(rounding) iOut += parseInt((number % 60000)/30001) ; break ; case 's': case 'S': iOut = parseInt(number / 1000 ) ; if(rounding) iOut += parseInt((number % 1000)/501) ; break ; default: // If we get to here then the interval parameter // didn't meet the d,h,m,s criteria. Handle // the error. alert(intervalMsg) ; return null ; } return iOut ; }
function dateDifference(strDate1,strDate2, interval, rounding) { datDate1= Date.parse(strDate1); datDate2= Date.parse(strDate2);
var iOut = 0; var number = datDate2-datDate1 ;
// what kind of add to do? switch (interval.charAt(0)) { case 'd': case 'D': iOut = parseInt(number / 86400000) ; if(rounding) iOut += parseInt((number % 86400000)/43200001) ; break ; case 'h': case 'H': iOut = parseInt(number / 3600000 ) ; if(rounding) iOut += parseInt((number % 3600000)/1800001) ; break ; case 'm': case 'M': iOut = parseInt(number / 60000 ) ; if(rounding) iOut += parseInt((number % 60000)/30001) ; break ; case 's': case 'S': iOut = parseInt(number / 1000 ) ; if(rounding) iOut += parseInt((number % 1000)/501) ; break ; default: // If we get to here then the interval parameter // didn't meet the d,h,m,s criteria. Handle // the error. alert(intervalMsg) ; return null ; } return iOut ; }
function displayCounter() { var intStartCount = 8000 var strDisplay var initialDate = new Date(2003,6,1); var currentDate = new Date() if (currentDate.getHours() > 12) { strDisplay = suycDateDiff(initialDate, currentDate, 'd', true) + intStartCount + 1 } else { strDisplay = suycDateDiff(initialDate, currentDate, 'd', true) + intStartCount } document.getElementById('spnCounter').innerText = strDisplay; } </script>
------------- Cheers
Normie
|