Skip to content

Date/Time

Working with dates and times in Dataverse can be surprisingly complex. One common issue is determining whether a DateTime value is stored in UTC or local time. For example, Dataverse stores DateTime fields in UTC internally, but depending on the field settings (User Local, Date Only, or Time-Zone Independent) and how you're accessing the data (e.g., through the SDK, OData, or Power Automate), the value you receive might be automatically converted—or not.

The IDateTimeService interface aims to solve these problems by providing easy to use methods for converting times to the expected values.

Example plugin using IDateTimeService
namespace Sample.Plugins
{
    using Imprevis.Dataverse.Plugins;

    public class TestPlugin : Plugin<TestPluginRunner> { }

    public class TestPluginRunner : IPluginRunner
    {
        public TestPluginRunner(IDateTimeService dateTime)
        {
            DateTime = dateTime;
        }

        public IDateTimeService DateTime { get; }

        public void Execute()
        {
            var globalTime = DateTime.GetUtc();
            var localTime = DateTime.GetLocal();

            // Do something!
        }
    }
}