Dates - Do you keep date formatting consistent across your application?

Last updated by Brook Jeynes [SSW] 7 months ago.See history

Date formats should always be kept consistent across your application, more importantly, it should be kept consistent with the operating system's regional settings otherwise this will cause significant confusion for your users.

BetterInterface RegionalSettings
Figure: Operating System's Regional Settings

Figure: Bad example - Screens with inconsistent date formats

Figure: Good example - Screens with consistent date formats

The best way to do this in your code is to grab the culture information from the application thread and use it to automatically format your Datetime data type. Do not use hard coded datetime formatting strings unless it's absolutely necessary.

startTimeTextBox.Text = resultResults.StartTime.ToString("dd/MM/yyyy hh:mm:ss");

Figure: Bad Example - Using hard coded formatting string

'Initial CultureInfo settings for the application
Public initialCulture As CultureInfo
txtDateCreate.Text = CType(txtDateCreate.Tag, System.DateTime).ToString(initialCulture.DateTimeFormat)

Figure: Good Example - Using culture info to format datetime

We open source. Powered by GitHub