If you have two date objects or one date object and you know the year, month and day to test for:
Code:
var cd=new Date(),
cy=cd.getFullYear(),
cm=cd.getMonth(),
cdate=cd.getDate();
This will give you 2008 as cy, cm would be 1 for Feb. (months start at 0 for Jan) and cdate would be 16 (or the current date number).
These can then be compared with similar from another date object or from set values. But the comparison is a little complicated:
Code:
<script type="text/javascript">
function when(){
var ty=2008, tm=1, tdate=16;
var cd=new Date(),
cy=cd.getFullYear(),
cm=cd.getMonth(),
cdate=cd.getDate();
if(cy<ty||cy==ty&&cm<tm||cy==ty&&cm==tm&&cdate<tdate)
return 'earlier'
if(cy==ty&&cm==tm&&cdate==tdate)
return 'today'
return 'later';
}
alert(when());
</script>
Bookmarks