Date format

Description

Date formating allows you to alter the date and time settings used by the server.

Discussion

You can easily deal with situations where the date format that a user wants to use is different than Regional Settings date format for your server. For example, assume that your server is on a machine in the US where the date format is 'MM/dd/yy'. Your users in the US who want to see and enter dates using the 'MM/dd/yy' format. However, your users in the rest of the world want to use the 'dd/MM/yy' format to display and enter date values.

The 'Date Format' property is used to customize the date format shown. The default for this property is 'MM/dd/yy', but you can select a different value.

You can override this property at runtime in Override Settings by setting the Grid's clientSideDateFormat property. For example:

tmpl.clientSideDateFormat = "dd/MM/yy"

You can also override this property at runtime by setting the special session.__protected__clientSideDateFormat variable. This is the more likely scenario as you can set this variable for each user when they log into your application.

Using the Device Culture's Date and Time Format 

You can specify that the date format, day names and month names for a component should be automatically selected based on the 'Accept-language' property in the request header when the browser makes a request. This makes it easier to build applications that seamlessly adapt based on the user's locale setting.

To use locale settings, set the date format to:

<cultureDateFormat>

If you also want to include time in the format, you can use the following:

<cultureDateFormat> <cultureTimeFormat>

You can also configure the day and month names to use the user's locale. See Date picker - day names and Date picker - month names to learn more.

See also Supporting Device Culture Codes and Setting the Date Format Based on the User's Locale.

Customizing Dates in Grid Controls 

When you configure the date picker for date and time fields, you will notice that the default value for the 'Format' property is an empty string. This indicates that the date picker format will be inherited from the global date format (set by the Grid's Date format property).

When you select a date or time field in the Grid or Detail View part, a default format is defined. The format is:

time("{grid.clientSideDateFormat}",<value>)

{grid.clientSideDateFormat} is a special placeholder that gets replaced at runtime with the value of the Grid's clientSideDateFormat property.

Assume that User1 logs on from New York. When User1 logs on, you set the special context.session.__protected__clientSideDateFormat variable to "MM/dd/yy". All dates in the Grid will appear in the MM/dd/yy format. When the user makes a selection from the Date Picker, the date will be entered in the MM/dd/yy format.

Assume that User2 logs on from London. When User2 logs on, you set the special context.session.__protected__clientSideDateFormat variable to "dd/MM/yy". All dates in the Grid will appear in the dd/MM/yy format.

When the user makes a selection from the Date Picker, the date will be entered in the dd/MM/yy format. When User1 or User2 submits data to the server, the date values are automatically converted to the format required by the Regional Settings of the machine on which the server is running.

This will all happen seamlessly, without requiring you to make any modifications to your Grid component.

If you are outside the US, you will probably want to change the default value for the Date Format to 'dd/MM/yy' for each new Grid that you build.

Month and Day Names 

You can customize the strings used for the month and day names in the date picker:

See Also