Bug 52243 - DatePicker date separators in custom format ignored
Summary: DatePicker date separators in custom format ignored
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: Low normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-02-02 10:51 UTC by Saskia
Modified: 2017-07-14 17:49 UTC (History)
4 users (show)

Tags: datepicker
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Saskia 2017-02-02 10:51:10 UTC
When setting the format of a datepicker to "MM/dd/yyyy" the date is shown as 02-20-2017.

The language on the device is set to Dutch. The default date format for the Dutch language is: dd-MM-yyyy.
So the order of day and month is changed with the custom format, but not the separator.

Kind regards, 
Saskia
Comment 1 Gert Jan Schoneveld 2017-03-06 09:26:14 UTC
It is not a bug, but a feature. The / is also a special formatting character. If you want the literal character, you have to escape it with a \ like @"MM\/dd\/yyyy"
Comment 2 Jimmy [MSFT] 2017-03-06 18:59:32 UTC
Just to clarify, the issue is that the default separator is used instead of "/", correct?

Can you try the suggestion from comment 1 and escape the '/' character to see if it helps? If it does not, please attach a reproduction project to the report so we can look into this further. Thanks!
Comment 3 Saskia 2017-03-07 06:48:48 UTC
Indeed. 
When the format is given as picker.Format = "MM/dd/yyyy"; 
The date is shown as 03-07-2017 (on a device with dutch language settings).

The workaround picker.Format = @"MM\/dd\/yyyy"; does give the correct date of 03/07/2017.

But I don't see how this can be a feature. Custom date formats are always given as e.g. "MM/dd/yyyy". And the formats are in resource files, dependent on the selected language. For the workaround I have to add an extra resource for date pickers, which increases the change of missing that format when something changes.
Comment 4 Rui Marinho 2017-06-20 18:17:36 UTC
This seems to have a correct answer by Jimmy
Comment 5 Saskia 2017-06-29 06:25:38 UTC
The workaround as suggested by Gert Jan works for now.

But I don't see that this can be a feature. As I said, custom date formats are always entered as "MM/dd/yyyy". So the behavior of the datepicker is inconsistent.

This bug should not have the resolved status.
Comment 6 Gert Jan Schoneveld 2017-06-29 07:30:14 UTC
The current behaviour is exactly as documented. That is why it is not a bug, but a feature.

"The "/" custom format specifier"
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#the--custom-format-specifier-1

"Using the Escape Character"
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#escape
Comment 7 Jimmy [MSFT] 2017-07-14 17:49:26 UTC
As also mentioned here[1], because the "/" character is not escaped it is interpreted as a format specifier that is replaced by the current culture date separator which is "-" in this case since the device language is Dutch. 

So Gert is correct in that you have to escape the character in order for it to be used as the date separator regardless of culture. As this is all handled by .Net and not Xamarin.Forms, I will go ahead and close this as answered. Thanks!

[1] https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo.dateseparator?view=netframework-4.7#remarks