# Overrride locale dateformat settings

**URL:** <https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182>\
**Category:** Classic Servoy\
**Created:** [September 23, 2014, 9:19am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182 "2014-09-23T09:19:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [September 23, 2014, 9:19am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/1 "2014-09-23T09:19:19Z")

</div>

Hi all, the locale.dateformat on server is set to ‘dd-MM-yyyy’, but I like to override this setting for a client. How can I do it? I only see a ‘getDefaultDateFormat’, method, but not a ‘setDateFormat’.

Regards,

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [October 16, 2014, 7:31am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/2 "2014-10-16T07:31:40Z")

</div>

Or is there an alternative? Our american users want to see date fields in us format, but spanish team want to see the fields in spanish format, and I don’t know how to do it…

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [October 23, 2014, 7:55am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/3 "2014-10-23T07:55:27Z")

</div>

problem with the system settings that they are global, they are not client specific (they are in the servoy.properties)

The best thing todo currently is for those fields that need those dateformats, don’t depend on the default value but set your value on the field (or columns level) and then use an i1i8n text instead of a direct format string  
Then you can add format strings per language/locale

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [May 10, 2016, 7:19am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/4 "2016-05-10T07:19:20Z")

</div>

We created first a valuelist like this:

d.M.yy 1.1.15|d.M.yy  
d.M.yyyy 1.1.2015|d.M.yyyy  
dd.MM.yy 31.12.15|dd.MM.yy  
dd.MM.yyyy 31.12.2015|dd.MM.yyyy  
dd-MM-yyyy 31-12-2015|dd-MM-yyyy  
dd/MM/yyyy 31/12/2015|dd/MM/yyyy  
MM/dd/yyyy 12/31/2015|MM/dd/yyyy  
yyyy-MM-dd 2015-12-31|yyyy-MM-dd

Then every user has a date format field in his settings and user record, where he can choose the format he likes.  
On startup, a global variable scopes.person.currentDateFormat\_dd\_mm\_yyyy is set to that field.

In the onShow() of a form where a date is involved, we set the format of each date field like this:

```auto
elements.ps_birthday.format = scopes.person.currentDateFormat_dd_mm_yyyy;

```

I do not know if there is a more easy method, but for us that works fine.  
The only disadvantage is that in table forms, you first see another format for some milliseconds.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [May 10, 2016, 7:56am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/5 "2016-05-10T07:56:14Z")

</div>

Even a better idea is to loop over all your forms with solution Model find your datefields, and change them accordingly.  
That is very fast, and no worry of doing it in onShow on every form.

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [May 10, 2016, 9:03am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/6 "2016-05-10T09:03:04Z")

</div>

As far as I remember, we need to call that line always in onShow(), so we can not put it in an  
if (firstShow)  
because the date format used to switch back when we did it only in firstShow.

But in case the looping with solutionModel works fine and that problem will not appear, it would be even better.

---

<div class="post-metadata">

**Author:** ![paronne](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/paronne/32/5096_2.png) [@paronne](https://forum.servoy.com/u/paronne)\
**Post date:** [May 10, 2016, 9:19am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/7 "2016-05-10T09:19:49Z")

</div>

> Harjo:  
> Even a better idea is to loop over all your forms with solution Model find your datefields, and change them accordingly.  
> That is very fast, and no worry of doing it in onShow on every form.

Harjo you mean to do that at the onSolutionOpen ? the solution suggested by Johan has less overhead since there is no need to iterate over all forms/elements at startup.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [May 10, 2016, 12:54pm UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/8 "2016-05-10T12:54:12Z")

</div>

> jcompagner:  
> problem with the system settings that they are global, they are not client specific (they are in the servoy.properties)
> 
> The best thing todo currently is for those fields that need those dateformats, don’t depend on the default value but set your value on the field (or columns level) and then use an i1i8n text instead of a direct format string  
> Then you can add format strings per language/locale

Hi Johan,

can you give an example? I’m not sure how you do that exactly

---

<div class="post-metadata">

**Author:** ![paronne](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/paronne/32/5096_2.png) [@paronne](https://forum.servoy.com/u/paronne)\
**Post date:** [May 10, 2016, 1:21pm UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/9 "2016-05-10T13:21:54Z")

</div>

You can add an i18n key called mykeys.settings.dateformat with value “dd-MM-yyyy”. On the format property of the field (or of the database column) you can then use i18n:mykeys.settings.dateformat. The format expression will then be evaluated as an i18n. So depending on your locale the i18n key for the dateformat may have a different value, therefore a different format is applied to the field.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [May 10, 2016, 1:34pm UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/10 "2016-05-10T13:34:35Z")

</div>

ah oke… thanks.  
never knew that! ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [May 10, 2016, 1:43pm UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/11 "2016-05-10T13:43:02Z")

</div>

May I add that language preference and date format preference of a single user is not necessary a one-to-one relation.  
I have seen users who even prefer the ISO-8601-date format YYYY-MM-DD (like today 2016-05-10).

By decoupling the date format from the language, and by giving all users the ability to choose whatever they want in their UI, the users get maximum personal freedom for the date format.

Of course, the date format that will be printed on invoices etc. is another story, that is more specific to the company itself, but could be managed in a similar way.

---

<div class="post-metadata">

**Author:** ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)\
**Post date:** [May 11, 2016, 9:17am UTC](https://forum.servoy.com/t/overrride-locale-dateformat-settings/18182/12 "2016-05-11T09:17:13Z")

</div>

One way of achieving the decoupling of the date format from the language and using the user preference suggested by Bernd but also keeping the efficiency of using an i18n string suggested by Johan would be to use the following in your solution startup (before any forms have loaded):

```auto
	if(scopes.person.currentDateFormat_dd_mm_yyyy)
		i18n.setI18NMessage('mykeys.settings.dateformat', scopes.person.currentDateFormat_dd_mm_yyyy);

```

In this manner if the user has selected a personalised format then that will be used otherwise the default for their locale will be used.

Steve
