Auto date convertion to local datetime on Cognitive search index issue

JF 1 Reputation point
2021-08-12T17:36:32.647+00:00

Our backend database is Mongodb and it stores date as UTC format by default. When we create the cognitive search indexes, it grabs the UTC date. This causes issues when we do the search as we need to search based on our local datetime. Is there anyway to auto convert the date coming from cognitive search index to local datetime if the source is UTC date format?

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
834 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 24,396 Reputation points Microsoft Employee
    2021-08-14T14:19:02.153+00:00

    @JF ,

    Azure Search accepts date/time values with full time zone information (Edm.DateTimeOffset) and then normalizes them to UTC for storage purposes. Azure Search itself will not convert date/times to different time zones. If you need to convert for the locale of each user on a per-search basis, then you will need to do the conversion on the client side.

    Please see the doc for more information: Edm.DateTimeOffset - Mapping between JSON Data Types and Azure Cognitive Search Data Types

    If your search client is a browser, you may implement this solution : Convert UTC date time to local date time using JavaScript | ref.

    1 person found this answer helpful.
    0 comments No comments