This is a migrated thread and some comments may be shown as answers.

Data Annotations Date Format

3 Answers 363 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Maurice asked on 05 Sep 2017, 11:40 AM

I am sure this was working but I am not seeing the correct output now:

Row Data Context Property

[Display(Name = "Start Date")]
[DisplayFormat(DataFormatString = "{0:d}")]
public DateTime ClaimDate { get; set; }

 

XAML in the View

<telerik:RadGridView VerticalAlignment="Stretch" CanUserDeleteRows="False" CanUserFreezeColumns="False" CanUserInsertRows="False" CanUserReorderColumns="False" CanUserSearch="False" ShowGroupPanel="False"
                       ShowSearchPanel="False" ItemsSource="{Binding Data.ItemsSource}" BorderBrush="Transparent" IsReadOnly="True" ShowToolTipOnTrimmedText="True" RowIndicatorVisibility="Collapsed"
                       SelectionMode="Single" IsFilteringAllowed="False" AlternationCount="2">
  </telerik:RadGridView>

 

C# Interactive Window

> DateTime.Today.ToString("d")
"05/09/2017"

 

Screenshots are attached.

 

Any ideas?

Thanks,
Maurice

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 08 Sep 2017, 09:03 AM
Hello Maurice,

I could not infer from your last reply what the exact issue at your end is. Could you please further clarify this?

From what I've seen in the image you provided, the results you get are expected because, as specified in the MS documentation on string formats:

"If the "d" format specifier is used without other custom format specifiers, it is interpreted as the "d" standard date and time format specifier." More information can be found in the Using single custom format specifiers section. In your case - this is the format when using {0:d} - MM/dd/YYYY.

Please let me know what the desired end result is and I will happily guide you toward the correct approach. I'm looking forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Maurice
Top achievements
Rank 1
answered on 21 Sep 2017, 07:52 AM

Sorry for some reason I didn't get an email saying there was a message reply.

The issue is that my local time (PC) is "dd/MM/", which is not being respected in my app showing 9/17/2017 or the  sample app grid columns, although the format at the bottom of the app is respecting the correct format for min/max values.

Regards,
Maurice

0
Dilyan Traykov
Telerik team
answered on 26 Sep 2017, 07:49 AM
Hello Maurice,

Could you please try both approaches suggested in this troubleshooting article and let me know if any of them works for you?

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Maurice
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Maurice
Top achievements
Rank 1
Share this question
or