Skip to content

Why Your Dataverse Date Is Off by a Day

I work from Kuala Lumpur, UTC+8, for Dutch customers on UTC+1. With seven hours between me and my users, Dataverse DateTime is something I can’t ignore.

Take a Dutch user who picks 8 February on a form. An integration reads the value and gets 7 February, 23:00. The user says the date is wrong. It isn’t. Dataverse stored exactly what it should: 8 February 00:00 in the Netherlands is 7 February 23:00 in UTC. The integration read a UTC value as if it were a local date.

Almost every DateTime bug I’ve seen in Dataverse comes down to three things. The integration contract is UTC. The UI converts time zones and the API doesn’t. And how a column stores its value is a different setting from how the form shows it.

Three rules every system follows

Most applications that deal with time zones follow the same rules:

  1. Store DateTime as UTC.
  2. Integrate DateTime as UTC.
  3. Show DateTime in the user’s local time zone, and only in the UI.

When the UI shows a value, it converts from UTC to the user’s time zone. When the user saves, it converts back to UTC before storing.

When you integrate through the API, nobody does that for you. Don’t assume it happens. If your integration shows a date to a user, the conversion to their time zone is your job.

What Dataverse does, and what it doesn’t

Dataverse follows those rules. The UI converts both ways, based on the time zone in the user’s personal settings.

The API doesn’t convert anything on the way in. Microsoft’s own Learn page has the cleanest example. A user in Pacific time submits 4 April 2021, 12:00:

  • Through the UI, Dataverse stores 2021-04-04T20:00:00Z and shows that user 12:00.
  • Through the Web API, without an offset, Dataverse stores 2021-04-04T12:00:00Z. The same user now sees 04:00.

Nothing is broken. Two paths, two answers.

If you have the user’s local time, send the offset with it:

{ "new_scheduledon": "2021-04-04T12:00:00-08:00" }

Or convert it yourself and send UTC:

{ "new_scheduledon": "2021-04-04T20:00:00Z" }

Never both an offset and a Z. Dataverse rejects that.

On the way out, the API returns the stored UTC value, and on request a formatted value. The formatted value is in the time zone and format of the user making the call. Show it to that user if you like, but never store it in another system. The moment a user in another time zone runs the same integration, the data stops agreeing with itself.

.NET and DateTime.Kind

In .NET the value you retrieve from a User local column is UTC, and the SDK sets the Kind to match:

var createdOn = entity.GetAttributeValue<DateTime?>("createdon");
Console.WriteLine($"DateTime: {createdOn.Value}, Kind: {createdOn.Value.Kind}");
// DateTime: 10/09/2022 08:44:57, Kind: Utc

Writing is where it goes wrong. A DateTime you create yourself has Kind Unspecified, and .NET treats that as local time:

var value = new DateTime(2023, 2, 13, 12, 0, 0);
Console.WriteLine($"{value}, Kind: {value.Kind}, UTC: {value.ToUniversalTime()}");
// 2/13/2023 12:00:00 PM, Kind: Unspecified, UTC: 2/13/2023 4:00:00 AM

On my machine in Kuala Lumpur, 12:00 became 04:00 UTC. The same shift happens when you write it to Dataverse. For a User local column, a value with Kind set to Utc is stored as is. Anything else is converted to UTC first, and that’s a conversion you didn’t ask for. So always set it yourself:

// The value is already UTC
entity["new_scheduledon"] = new DateTime(2027, 2, 8, 9, 0, 0, DateTimeKind.Utc);

// You got a DateTime from somewhere else and know it's UTC
entity["new_scheduledon"] = DateTime.SpecifyKind(value, DateTimeKind.Utc);

Kind is read-only on an existing DateTime. SpecifyKind returns a new one.

The same applies inside a plugin: work in UTC and convert only when you show a value to a person.

Power Automate

The Dataverse connector follows the same contract as a plugin. Send UTC and Dataverse handles the rest.

Two expressions do most of the work, and they’re easy to mix up:

formatDateTime(utcNow(), 'yyyy-MM-dd HH:mm')
convertTimeZone(utcNow(), 'UTC', 'W. Europe Standard Time', 'yyyy-MM-dd HH:mm')

formatDateTime changes how a value looks. It doesn’t change the time zone. Only convertTimeZone does that, and both return a string.

The three DateTime behaviors

Every DateTime column has a behavior. It decides how Dataverse stores the value and whether it converts it.

BehaviorWhat is storedWeb API typeUse it for
User local (default)UTCDateTimeOffsetMeetings, deadlines, anything where the time zone matters
Time zone independentExactly what was entered, no conversionDateTimeOffsetHotel check-in, store opening hours
Date onlyA date, no timeDateBirthdays, contract dates

User local is everything I described above.

Time zone independent stores what you see on the screen, for every user anywhere. It still has a time, so time calculations work. One trap: the Web API returns it as 2020-06-26T14:00:00Z. That Z doesn’t mean UTC. It means “as stored”. Don’t convert it.

Date only is a true date. The Web API returns 2020-06-26, with no time at all. The time-based query operators don’t work on it: Older Than X Minutes, Older Than X Hours, Last X Hours and Next X Hours.

Format is not behavior

This is where most off-by-one-day bugs come from.

Next to the behavior, every DateTime column has a format: Date and time, or Date only. The format only decides what the form shows. A User local column with Date only format still converts.

A user in UTC-8 enters only the date 14 October 2023 on a User local column with Date only format. Dataverse stores 2023-10-14T08:00:00Z.

Now take a user in Kuala Lumpur. They pick 8 February on the same kind of column. Dataverse stores 7 February, 16:00 UTC. Every integration that takes the date part of that value gets 7 February.

The form showed a date picker, so everyone assumed it was a date. It was a UTC timestamp all along.

In the maker portal, the Date only format defaults to Time zone independent behavior. Through code, a new column defaults to User local, whatever the format. So always double-check what is being created.

Choose before there’s data

Behavior is the one setting you want right the first time.

A User local column can change once, to Date only or Time zone independent. A column created as Date only or Time zone independent can never change. createdon and modifiedon are User local and stay that way. And when you do change a column, the values already in the database don’t convert by themselves.

Nick Doelman has a story about this. The ReadyXRM post on date and time columns apologises to the folks in Vancouver who showed up at 6am for a class that was really supposed to start at 9am. A user in Ontario had scheduled it.

Changing a date and time column that already holds data is its own procedure, with its own traps. That’s a separate post.

A date in Dataverse is almost never wrong. It’s in a different time zone than you assumed.

Earns Its Keep

Every Sunday, one post on Dataverse, .NET, and whether the tools we rely on still deserve to be there.