Blog Post

Messaging on Azure Blog
1 MIN READ

How to use DateTime in a SqlFilter with .NET

AshishChhabria's avatar
AshishChhabria
Former Employee
Mar 15, 2019
First published on on Jun 08, 2016
Have you been wondering how to use DateTime inside of SqlFilters, with your Topics/Subscriptions? Have you also noticed that this doesn't seem to work?
var message = new BrokeredMessage();
message.Properties["datetime"] = DateTime.Now;

var sqlFilter = new SqlFilter("datetime > '2016-06-06'");

That's because you explicitly need to add the DateTime as a parameter, like so:
var filter = new SqlFilter(" datetime >= @datetime");
filter.Parameters.Add("@datetime", DateTime.Parse("2016-06-06"));

In order to make this more searchable in the future, I have also added a corresponding StackOverflow question: http://stackoverflow.com/questions/37705333/azure-service-bus-using-datetime-in-topic-subscription-sqlfilter-in-net
Updated Mar 15, 2019
Version 2.0
No CommentsBe the first to comment