back to top

Displaying Date/Times Correctly Using the User Timezone in the Infor CRM Web Client

The Infor CRM web client handles date/times a little differently than in the LAN client. When you retrieve a date in the LAN client it returns the date based on applying an offset to the UTC database value based on your computer’s timezone. In the web client it acts a bit differently. Because the web server may be running in a different timezone than the clients it is serving, simply returning a UTC offset based on the web server’s timezone would not give accurate results. Because of this, when you retrieve a date field via the entity model it is returned as its straight UTC value, just like if you looked at it in the database.

When you bind a date field to a date control in the web UI, that date control automatically handles converting the bound UTC value to the correct local time based on the computer’s timezone that the browser is being ran on. So handling date/times on bound controls is easy. But what about if you want to work with date/time values on server-side code? Let’s say you want to place a date value within a string along with other text. Because this code will be running on the web server, you have to know how to handle things in order for the date/time to look correct for the user.

Lets take a look at how to do that.

The first thing to know is that there is a client context service which lets you pass items between the server side and the client side of a web client session. You access that by getting a reference to its service like so:

var context = ApplicationContext.Current.Services.Get<Sage.Platform.Application.IContextService>(true);

One of the items that is set on the client side is the browser’s Timezone upon logging in. With that information we can make a call to our context service reference to get that timezone value which was set from the client side and use it from the server side. Sage has implemented a Timezone class to translate that stored timezone into an object that can be used and that has useful methods.

var timeZone = (Sage.Platform.TimeZone)context.GetContext("TimeZone");

The most relevant method of the TimeZone class is a function to convert a UTC date/time to the local date time. This function accepts a DateTime object and returns a DateTime object that can be used as normal but with the UTC date converted to the “users” local time.

Lets look at an example. Lets say we have an Account with a CreateDate stored in the database with a value of “2022-09-17 17:25:57.000” This means that the record was created at 5:25PM UTC time.

If we were to do something like this:

IAccount acc = this.BindingSource.Current as IAccount;
string myDateTest = string.Format("What is this? {0:MM/dd/yyyy h:mm tt}", acc.CreateDate);

Then myDateTest would return “What is this? 09/17/2022 5:25 PM”

Now, let’s imagine that I am a client running a web browser on a computer set to the USA Central timezone. If I were to utilize the timezone context from the server like this:

IAccount acc = this.BindingSource.Current as IAccount;
var context = ApplicationContext.Current.Services.Get<Sage.Platform.Application.IContextService>(true);
var timeZone = (Sage.Platform.TimeZone)context.GetContext("TimeZone");
DateTime dt = timeZone.UTCDateTimeToLocalTime((DateTime)acc.CreateDate);
string myDateTest = string.Format("What is this? {0:MM/dd/yyyy h:mm tt}", dt);

Then myDateTest would return “What is this? 09/17/2022 10:25 AM” which is the Central timezone equivalent of the UTC value “2022-09-17 17:25:57.000”.

Please note that most dates in the system are nullable DateTime? data types so before you go using that UTCDateTimeToLocalTime check that your date/time has a value to avoid null reference errors.

Also, please note that if you are using this kind of code, and storing the result somewhere, the context of the value returned is only “true” for people running a browser in the same time zone as the user who ran the code and set the value initially. For instance if you are trying to put the date into a memo field, everyone will see “What is this? 09/17/2020 10:25 AM” which will confusing for someone say in California, or New York to know that the 10:25AM time was true for a user in the Central time zone. Instead I would recommend including the timezone used, like this:

IAccount acc = this.BindingSource.Current as IAccount;
var context = ApplicationContext.Current.Services.Get<Sage.Platform.Application.IContextService>(true);
var timeZone = (Sage.Platform.TimeZone)context.GetContext("TimeZone");
DateTime dt = timeZone.UTCDateTimeToLocalTime((DateTime)acc.CreateDate);
string myDateTest = string.Format("{0} {1}",
  timeZone.UTCDateTimeToLocalTime((DateTime)acc.CreateDate).ToString("MM/dd/yyyy h:mm tt"), 
  timeZone.StandardName);

Then myDateTest would return “What is this? 09/17/2022 10:25 AM Central Standard Time” which allow people to understand what that time referred to.

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Kris Halsrud
Kris Halsrud
Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Infor CRM SLX 10.0: Delegate Ownership Changes for “Everyone” Records

Learn how the new EveryoneOwnerAssignment secured action in Infor CRM SLX 10.0 allows designated users to change ownership of Everyone-owned records without requiring Administrator access.

Related Articles

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Related Videos