Introduction

This article documents the basics of using Date and time fields in Dynamics CRM.

Basic Concepts

(1) Dataverse stores all date and time values in the UTC time zone. When the application displays values or processes user-entered values, Dataverse and model-driven applications can use the “Format” option to adjust to the user’s time zone.

(2)When an entity creates a new Date and time' field, the following format can be selected:

FormatDescription
Date onlyThe date and time values displayed. The time value is stored in the system as 12:00 AM (00:00:00)
Date and timeDate and time values
Select Format for ‘Date and time’ fields

Select Format for ‘Date and time’ fields

(3) When an entity creates a new Date and Time field, the following Time Zone Adjustment option is available in the Advanced Options.

In addition, the available options for Time Zone Adjustment vary according to the Format as follows:

Format When Date only is selected, Time Zone Adjustment can be selected:

Time Zone AdjustmentDescription
User localDefault value. Adjusts the value according to the user’s time zone
time zone independentDisplay values without time zone conversion
Date onlyNo time zone conversion. Unlike time zone independence, no time portion is stored ( Time values are stored in the system as 12:00 AM (00:00:00) )

Format When Date and time is selected, Time Zone Adjustment can be selected:

Time Zone AdjustmentDescription
User localDefault value. Adjusts the value according to the user’s time zone
Time zone independentDisplay values without time zone conversion

Can Format and Time zone adjustment be changed again?

Is it still possible to modify the format and Time zone adjustment of a Date and time field that has already been created?

The results are verified as follows:

Format and Time Zone AdjustmentFormatTime Zone Adjustment
Date only - User local
Date only - time zone independentX
Date only - Date onlyXX
Date and time - User local
Date and time - time zone independentX

How should I choose the Time zone adjustment?

Time zone adjustment optionsDescription
Time zone independentUse this option when time zone information is not required, e.g. hotel check-in time, invoice payment time, etc. When this option is selected, users in all time zones will see the same date and time values
Date onlyUse this option when not focusing on the time of day or time zone, such as birthdays or anniversaries, etc. When this option is selected, users in all time zones will see the exact same date values.
Note
  1. “Date Only - Time Zone independent is the same as ‘Date Only - Date Only’, and if you are unsure whether the ‘Date and Time’ field will need a time component (hours, minutes, and seconds) in the future, you should Select “Date Only - Time Zone independent.

  2. Since the system defaults to “user local, we need to be careful if we need to select “date only” or “time zone independent” (at least for clear requirements), otherwise Users in different time zones will see different dates due to ±8 hours.

Small experiment

I’ll add the following five new date and time fields to the Invoice entity, assign values to them, and then use them to see the original values stored in the database

Information
  1. The time zone I’m currently using is (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi
  2. The time zone used by user Test06 is (GMT+04:00) Baku

(1)New Fields

The 5 ‘Date and time’ fields are as follows:

NameField NameFormatTime zone adjustment
D - User Localgdh_d_userlocalDate OnlyUser local
D - TZ independentgdh_d_tz_independentDate OnlyTime zone independent
D - Dgdh_d_dDate OnlyDate Only
DT - User Localgdh_dt_userlocalDate and timeUser local
DT - TZ independentgdh_dt_tz_independentDate and timeTime zone independent
The 5 ‘Date and time’ fields

The 5 ‘Date and time’ fields

(2)Fill in the “Date and Time” field in the form

Assigns a value to a field in the (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi time zone:

FieldFill in a form
D - User Local2025-03-10
D - TZ independent2025-03-12
D - D2025-03-14
DT - User Local2025-03-10 14:30
DT - TZ independent2025-03-24 09:30
Fill in the “Date and Time” field in the form

Fill in the “Date and Time” field in the form

(3)Viewing data in the database

Viewing data in the database

Viewing data in the database

The results are as follows:

FieldFill in a formDatabase value
D - User Local2025-03-102025-03-09 16:00:00.000
D - TZ independent2025-03-122025-03-12 00:00:00.000
D - D2025-03-142025-03-14 00:00:00.000
DT - User Local2025-03-10 14:302025-03-10 06:30:00.000
DT - TZ independent2025-03-24 09:302025-03-24 09:30:00.000
为Why `D - User Local` is stored in DB as `2025-03-09 16:00:00.000` when I filled in `2025-03-10`?

I am assigning D - User Local in (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi time zone, and the time is 2025-03-10.

But in the database, the time is stored in the UTC time zone, and there is an 8 hour time difference between East 8 and UTC.

So the local date of 2025-03-10 becomes 2025-03-09 16:00:00.000 when it is converted to the UTC time zone.

Same for DT - User Local.

Sql code
SELECT gdh_d_userlocal AS 'D - User Local',
       gdh_d_tz_independent AS 'D - TZ independent',
       gdh_d_d AS 'D - D',
       gdh_dt_userlocal AS 'DT - User Local',
       gdh_dt_tz_independent AS 'DT - TZ independent'
FROM   gdh_invoice
WHERE  gdh_no = 'SAS-00000001';

(4)Viewing Data with Test06

Note: The time zone used by user Test06 is (GMT+04:00) Baku.

Viewing Data with Test06

Viewing Data with Test06

Why does user Test06 see D - User Local on the form as 2025-03-10 10:30:00.000?

The time stored in the database by D - User Local is 2025-03-10 06:30:00.000 (UTC time zone).

When this time is converted to the time zone of user Test06: “(GMT+04:00) Baku”, the

the time becomes 2025-03-10 10:30:00.000 (UTC + 4).

So the D - User Local that user Test06 sees on the form is 2025-03-10 10:30:00.000

(4)Use the Client API to get

a. Get D - User Local and DT - User Local value.

NameField NamesFormatTime Zone AdjustmentFill in under GMT+08:00 time zone
D - User Localgdh_d_userlocalDate onlyUser Local2025-03-10
DT - User Localgdh_dt_userlocalDate and timeUser Local2025-03-10 14:30
# 'Sun, 09 Mar 2025 16:00:00 GMT'
Xrm.Page.getAttribute("gdh_d_userlocal").getValue().toUTCString(); 

# 'Sun, 09 Mar 2025 16:00:00 GMT'
Xrm.Page.getAttribute("gdh_d_userlocal").getValue().toUTCString(); 

b.For “Time zone independent”, the timezone of the browser is returned

Get D - TZ independent and DT - TZ independent value.

NameField NamesFormatTime Zone Adjustment
D - TZ independentgdh_d_tz_independentDate onlyTimezone independent
DT - TZ independentgdh_dt_tz_independentDate and timeTimezone independent
# 'Wed Mar 12 2025 00:00:00 GMT+0800 (China Standard Time)'
Xrm.Page.getAttribute("gdh_d_tz_independent").getValue().toString(); 

# 'Mon Mar 24 2025 09:30:00 GMT+0800 (China Standard Time)'
Xrm.Page.getAttribute("gdh_dt_tz_independent").getValue().toString(); 
Noteworthy

JavaScript date values are affected by the browser’s time zone (from the device OS settings), so care should be taken:

  1. for the field “User Local Time”, the Client API gets the result as a “UTC” value and should use Date.getUTCDate(), Date.getUTCHours() instead of Date.getDate().

  2. apply getTimeZoneOffsetMinutes if you want to get the time the user sees. Don’t use Date.getDate(), Date.getHours(), etc., as they show the browser’s timezone

  3. For “timezone-independent” and “date-only” fields, you should use Date.getDate(), Date.getHours(), etc., instead of Date.getUTCDate(), Date.getUTCHours(), as there is no need for timezone conversion.

(5)Using Web API to Retrieve Data

Assign values to fields in the (GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi timezone and retrieve them using a Web API:

FieldInput ValueStored Value in DatabaseRetrieved via Web API
D - User Local2025-03-102025-03-09 16:00:00.0002025-03-09T16:00:00Z
D - TZ independent2025-03-122025-03-12 00:00:00.0002025-03-12T00:00:00Z
D - D2025-03-142025-03-14 00:00:00.0002025-03-14
DT - User Local2025-03-10 14:302025-03-10 06:30:00.0002025-03-10T06:30:00Z
DT - TZ independent2025-03-24 09:302025-03-24 09:30:00.0002025-03-24T09:30:00Z

It can be observed that the raw value retrieved via the Web API is the same as the value stored in the database.

Note

What do “T” and “Z” mean in “gdh_dt_userlocal”: “2025-03-10T06:30:00Z”?

  • T

    • “T” is a special character in the ISO 8601 datetime format used to separate the date and time parts.
    • For example, 2025-03-10T14:30:00 represents March 10, 2025, at 14:30:00.
  • Z

    • “Z” is a special character in the ISO 8601 datetime format, representing “Zulu time” or UTC (Coordinated Universal Time).
    • It indicates that the time is expressed in UTC with no time zone offset.
    • For example, 2025-03-10T14:30:00Z represents March 10, 2025, at 14:30:00 (UTC time).
Web API 代码
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/gdh_invoices(98F83878-1E35-EF11-8409-0017FA0671FA)?$select=gdh_d_d,gdh_d_tz_independent,gdh_d_userlocal,gdh_dt_tz_independent,gdh_dt_userlocal", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var gdh_d_d = result["gdh_d_d"];
            var gdh_d_tz_independent = result["gdh_d_tz_independent"];
            var gdh_d_userlocal = result["gdh_d_userlocal"];
            var gdh_dt_tz_independent = result["gdh_dt_tz_independent"];
            var gdh_dt_userlocal = result["gdh_dt_userlocal"];
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

Query Operators Not Supported?

For “date-only” type date and time fields, the following query operators are not allowed. Using these operators in queries will result in an invalid operator exception error.

  • X minutes ago
  • X hours ago
  • Past X hours
  • Next X hours

For example, when filtering the “D-D” column, the filter conditions are as follows:

<condition attribute="gdh_d_d" operator="last-x-hours" value="5"/>

filtering the D-D column

filtering the D-D column

An error is reported after execution:2147779605The operator is not valid or it is not supported.

Error:2147779605The operator is not valid or it is not supported.

Error:2147779605The operator is not valid or it is not supported.

How to Set the User’s Time Zone?

Click the Settings button in the top right corner –> Personalization Settings –> General Tab –> Select Time Zone.

Set the User’s Time Zone

Set the User’s Time Zone

Refer

  1. Column Data types
  2. Column Data types