Sitecore SOLR error: Invalid Date in Date Math String

There seems to be an issue with certain combinations of Sitecore, SOLR and the local machine datetime settings. This is the error:

ManagedPoolThread #11 12:20:50 INFO Job started: Index_Update_IndexName=sitecore_master_index
ManagedPoolThread #11 12:20:50 ERROR Exception
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
at Sitecore.Jobs.JobRunner.RunMethod(JobArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Jobs.Job.ThreadEntry(Object state)

Nested Exception

Exception: SolrNet.Exceptions.SolrConnectionException
Message: <?xml version=”1.0″ encoding=”UTF-8″?>
<lst name=”responseHeader”><int name=”status”>400</int><int name=”QTime”>46</int></lst><lst name=”error”><str name=”msg”>Invalid Date in Date Math String:’2017-03-20T13.56.31Z'</str><int name=”code”>400</int></lst>

Source: SolrNet
at SolrNet.Impl.SolrConnection.PostStream(String relativeUrl, String contentType, Stream content, IEnumerable`1 parameters)
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s)
at SolrNet.Impl.SolrBasicServer`1.SendAndParseHeader(ISolrCommand cmd)
at Sitecore.ContentSearch.SolrProvider.SolrBatchUpdateContext.AddRange(IEnumerable`1 group, Int32 groupSize)
at Sitecore.ContentSearch.SolrProvider.SolrBatchUpdateContext.Commit()
at Sitecore.ContentSearch.AbstractSearchIndex.PerformUpdate(IEnumerable`1 indexableInfo, IndexingOptions indexingOptions)

Nested Exception

Exception: System.Net.WebException
Message: The remote server returned an error: (400) Bad Request.
Source: System
at System.Net.HttpWebRequest.GetResponse()
at HttpWebAdapters.Adapters.HttpWebRequestAdapter.GetResponse()
at SolrNet.Impl.SolrConnection.GetResponse(IHttpWebRequest request)
at SolrNet.Impl.SolrConnection.PostStream(String relativeUrl, String contentType, Stream content, IEnumerable`1 parameters)

The error is thrown by SOLR when a datetime string have an invalid format. SOLR only allows datetime strings in the format of YYYY-MM-DDThh:mm:ssZ.

Please note that in the error message above, the format is in fact wrong, as the time contains . instead of :

  • Wrong: 2017-03-20T13.56.31Z
  • Correct: 2017-03-20T13:56:31Z

My machine is configured so the time format contains . not :, and that is why SOLR gets the wrong format.

2017-10-25_13-10-27-3Sitecore have addressed this in patch 178247, where they modify the default System.DateTime converter to ignore any local culture info. The configuration change is simple:

<configuration xmlns:patch="" xmlns:set="">
              <converter handlesType="System.DateTime" typeConverter="Sitecore.ContentSearch.Converters.IndexFieldUTCDateTimeValueConverter, Sitecore.ContentSearch" set:typeConverter="Sitecore.Support.ContentSearch.Converters.IndexFieldUTCDateTimeValueConverter, Sitecore.Support.178247"/>

And the code change very small:

namespace Sitecore.Support.ContentSearch.Converters
  public class IndexFieldUTCDateTimeValueConverter : IndexFieldUtcDateTimeValueConverter
    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
      culture = CultureInfo.InvariantCulture;
      return base.ConvertTo(context, culture, value, destinationType);

Thanks to Sitecore support for the patch.


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 and tagged , , . Bookmark the permalink.

2 Responses to Sitecore SOLR error: Invalid Date in Date Math String

  1. Jan Sommer says:

    Thanks, the fix worked immediately! .NET defaulting to using the server’s culture have caused soooo many headaches.


  2. Pingback: Invalid Date in Date Math String error with Computed field in Sitecore with Solr | Sitecore basics!

Leave a Reply

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

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.