Reading Date from Database in the incorrect Format

886 Views Asked by At

I have a date fields in a SQL database which are stored in date and datetime2 format.

When executing the Read method on the SmartObject linked to this table, it tries to force the date into an American Format (MDY), and either display this date if it is valid, or fails to show anything (i.e. if the day is above 12)

However, when executing the List method, the data seems to display correctly, as it does when using the SmartObjectTester to execute the Read method on the object.

Is there a way to prevent this from happening, and to have the Date field be read in DMY format, and thus display correctly?

2

There are 2 best solutions below

0
On BEST ANSWER

This problem came from having the configuration of the Web.config set up to use a different culture to the one which the server K2 was installed on is using.

To solve this, ensure they are the same, and the Server should be able to read from the DB correctly, and thus display on the SmartForms without switching the dates around.

The relevant line to change in the Web.Config is

<add key="SmartObject.ExecutionCulture" value="en-US" />
0
On

You can change the Data Type of the Field and in the Style Builder Change the "Date and Time" setting to use the format you need. Its always best to use User Settings. Style Builder for Date