A note about DateTime queries in Azure

While running a query in Azure based on the last updated time (I had a DateTime  field in my table), I was not getting the results I expected. I had rows whose last updated time was over an hour ago, and I was running a query that would return all records over an hour old, but I wasn’t getting those rows back.

The problem was that I was using a GETDATE() call in the stored procedure, which was in SQL Azure. However, the time that I was using to pull the records was in my local development environment. The time on the Azure site were quite different than on my system.

There are a couple ways to solve this. Using UTC time is one way. Consistently using the GETDATE() call so that it is used in the same environment is another. (Calling the function only on the SQL Azure database, or passing in a DateTime from an application as a parameter to a stored procedure.) I went with the latter, and it worked fine. Just something to keep in mind.

  1. Leave a comment

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: