Data Annotations Date Format

4 posts, 0 answers
  1. Maurice
    Maurice avatar
    8 posts
    Member since:
    Feb 2014

    Posted 05 Sep Link to this post

    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

     

     

     

     

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 08 Sep Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Maurice
    Maurice avatar
    8 posts
    Member since:
    Feb 2014

    Posted 21 Sep in reply to Dilyan Traykov Link to this post

    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/yyyy", which is not being respected in my app showing 9/17/2017 or the telerik sample app grid columns, although the format at the bottom of the telerik app is respecting the correct format for min/max values.

    Regards,
    Maurice

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 26 Sep Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top