Working with dates in the SalesLogix Web Client

The SalesLogix database stores most dates in the database in UTC time.  In the SalesLogix web client, the SalesLogix date controls automatically handle converting a bound date time to the local web client’s time zone from the UTC equivalent.  The same is not true when retrieving dates and using them on other controls, like labels.  Let’s take a look at some of the ways we can work with date time values in the SalesLogix web client:

Lets say we have a date time of 6/18/2012 11:00AM central time with a UTC equivalent of 6/18/20012 4:00PM.

Lets us also assume the web server is in central time and the client computer running the SalesLogix Web Client is in the eastern time zone.

DateTime utcDate= new DateTime(2012, 6, 18, 16, 00, 00);

Option 1- Direct binding of a text box with a date time:

txtBox.Text = utcDate.ToString();

This will return the date time with no conversion.  6/18/20012 4:00PM.

Option 2-  Binding a text box control using server time:

Sage.Platform.TimeZones tzs = new Sage.Platform.TimeZones();
Sage.Platform.TimeZone tz = tzs.CurrentTimeZone;
DateTime? x = tz.UTCDateTimeToLocalTime(utcDate);
txtBox.Text = x.Value.ToString();

This will return the date time in the server’s local time zone since this server side code is running on the web server.  6/18/20012 11:00AM.

In order to return the local time equivalent (Eastern Time Zone) we need to switch from server side conversion to client side conversion.  We can do this as option 3.

Option 3-  Binding a text box control using client side time:

txtBox.Text = utcDate.ToString();

//Client side script to show local client time based on UTC conversion using JS date function toLocaleString
string clientscript = string.Empty;
clientscript = “var sdt = document.getElementById(‘” + txtBox.ClientID + “‘).value + ‘ UTC’;”;
clientscript += “var d = new Date(sdt);”;
clientscript += “var lbl = document.getElementById(‘” + txtBox2.ClientID + “‘);”;
//clientscript += “lbl.value = d.toLocaleString();”; //Returns full date formatted differently then other dates so following formats date equally
clientscript += “lcldt = new Date(d.toLocaleString());”;
clientscript += “var formattedDT = lcldt.getMonth() + ‘/’ + lcldt.getDate() + ‘/’ + lcldt.getFullYear() + ‘ ‘ ;”;
clientscript += “var Hours = lcldt.getHours(); var PM = false;”;
clientscript += “if (Hours>12) {PM=true; Hours = Hours -12;}”;
clientscript += “formattedDT = formattedDT + Hours + ‘:’ + lcldt.getMinutes() + ‘:’ + lcldt.getSeconds();”;
clientscript += “if(PM) formattedDT = formattedDT + ‘ PM’; else formattedDT = formattedDT + ‘ AM’;”;           
clientscript += “lbl.value = formattedDT;”;
ScriptManager.RegisterStartupScript(Page, GetType(), “UniqueInjectedScriptName”, clientscript, true); 

Here in this sample we are doing a server side binding of a text box, with no conversion.  The time would show as 6/18/20012 4:00PM.  However, we are also then injecting java script onto the form that examines the bound text box control, gets the date value and then using the Java script’s Date.toLocaleString function converting the UTC equivalent to the browser’s local time.  We then set the text box back to display that time which will be 6/18/20012 12:00PM.

So there you have it, three scenarios to work with dates in the SalesLogix web client.  Of course the SalesLogix date control already does all of this for you with the server side a client side libraries associated with the control OOTB.


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!