Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to best deal with rounding errors when comparing dates/times

$
0
0

I have a column that contains a series of date/time values. I am wanting to determine how many of the time slots fall between 10:00 and 11:00 am, 11:00 am and noon, etc. To pull the time out of my date/time entry I am using the formula "=A1 - int(A1)", where A1 is the date/time. However, this is giving me weird rounding errors at the 10th or so decimal place. This error in rounding pulls the extracted time value above or below the "expected" value for a given time, so I hesitate to simply round my values to a given decimal place. How do folks generally work around this?

To give an example, 8 pm is 0.83333333333333. Using the "int" formula to pull the time from my given date, I get 0.833333333328483, making that particular entry be listed as happening between 7 and 8 as opposed to between 8 and 9.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>