Datediff with milliseconds (ms)

I advised a developer to compare dates with milliseconds, but it ended up blowing up with overflow.  If you compare the milliseconds for dates that are months apart, it is a very large number!

Error message:
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

A way around this is to compare the dates by minutes first, and then apply the milliseconds comparision.  This will prevent the comparison of dates that are too wide apart.

WHERE  DATEDIFF( m, Date1, Date2 ) < 1
AND DATEDIFF( ms, Date1, Date2 ) < 500

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s