13 August 2012

Solr date formats in C#

The Solr search engine requires dates to be in the UTC format. Using C# to create a Solr crawler, I came across a challenge as the engine would not accept the default dates. It kept throwing errors: "Error adding field". Some research revealed that Solr expects dates to always end with the "Z" character. This handy page showed the different String.Format() patterns to get just about any date string you need. This one worked for Solr:
var date = String.Format("{0:yyyy-MM-ddTHH:mm:ss.fffffffZ}", 
    dateObjectToFormat);
This produces a date in this format in Solr:
2010-03-09T00:00:00Z
Check out this documentation on the Solr date formats.

1 comment:

Anonymous said...

Whoa! This blog looks exactly like my old one! It's on a totally different topic but it has pretty much the same page layout and design. Outstanding choice of colors!
My web blog Mixed Martial Arts rankings