I am looking for a way to do the correct subtraction between two Date javascript objects and get the delta of the day.
This is my approach, but it is not suitable for today's date as input:
<script type="text/javascript"> function getDayDelta(incomingYear,incomingMonth,incomingDay){ var incomingDate = new Date(incomingYear,incomingMonth,incomingDay); var today = new Date(); var delta = incomingDate - today; var resultDate = new Date(delta); return resultDate.getDate(); } //works for the future dates: alert(getDayDelta(2009,9,10)); alert(getDayDelta(2009,8,19)); //fails for the today as input, as expected 0 delta,instead gives 31: alert(getDayDelta(2009,8,18)); </script>
What would be better for this?
javascript date datetime
Hellnar
source share