Date Range Timer
This revolves around a javascript function: checkDate(date1,date2)
It calculates and compares dates based on Mountain Standard Time, allowing for daylight savings.
jQuery
There is a jQuery call on every page to automatically handle elements with "data-start" or "data-end" defined:
- Assign an element the attribute(s) of "data-start" or "data-end"; The element will be hidden initially and will not appear unless it matches the date criteria.
- You can apply these attributes within the element's tag to create a start date, and end date, or both (a range).
- Dates must be provided in this form: "
August 2, 2013 13:30:00
". The timezone is MST (-7/-6 offset).
<div data-start="October 13, 1975 11:13:00"
data-end="August 2, 2013 09:13:00"></div>
<div data-start="August 2, 2013 07:50:00"></div>
<div data-end="August 2, 2013 08:28:00"></div>
Custom
You can manually call checkDate() in your own functions and elements:
- checkDate(startdate,enddate) returns true if the current MST time:
- Falls after startdate
- Falls before enddate
- Falls between startdate and enddate (if both are specified)
- checkDate(startdate,enddate) returns false otherwise
<div id="custom">
Color Me
</div>
<script>
var elem = document.getElementById('custom');
var startdate = 'October 1, 1985 23:59:00';
var enddate = 'October 1, 2015 00:00:00';
if (checkDate(startdate,enddate)==true) {
// falls within date range
elem.style.border='1px solid red';
}
if (checkDate(startdate,'')==true) {
// falls after startdate
elem.style.color='green';
}
if (checkDate('',enddate)==true) {
// falls before enddate
elem.style.backgroundColor='#eeeeee';
}
</script>
Color Me