How to change datetime format in FilterExpression?

5 posts, 0 answers
  1. Jon
    Jon avatar
    4 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post

    I'm working on multi-language web application where one of the languages is simplified chinese.  I'm using custom paging, which in turn means I have to handle custom filtering as well, which is major PITA.

    ORM I'm using doesn't support LINQ.  So I came up with a plan to simply use contents of FilterExpression as part of the sql to retrieve data from database.

    Problem is datetime format for simplified chinese looks like yyyy年M月d日.  Say user selects 25 Jul 2013 in GridDateTimeColumn filter, then FilterExpression becomes ([LastUpdateDate] >= '2013年7月25日 0:00:00'), which sql server doesn't recognise at all.  I tried changing FilterDateFormat, but that defines how date is displayed in the filter.

    Funny thing is default filtering works ok, but of course it doesn't work with custom paging.  Is there any way to customise datetime format in FilterExpression?
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 13 Aug 2013 Link to this post

    Hi Jon,

    When using GridDateTimeColumn you could set the "FilterDateFormat" and "EditDataFormatString" properties for the date format.

    In your case, where custom filtering is used, you could parse the date from the filter to a culture of your choice as shown bellow:
    DateTime dateTime = new DateTime();
    CultureInfo info = new CultureInfo("en-US");
    dateTime = DateTime.Parse("2013年7月25日 0:00:00", info);
    //string customDateFormat = string.Format("{0:MM/dd/yy H:mm:ss zzz}", dateTime.ToString());

    Hope that helps.

     

    Best Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. Ryan
    Ryan avatar
    39 posts
    Member since:
    Jun 2016

    Posted 18 Dec 2017 in reply to Konstantin Dikov Link to this post

    The FilterDateFormat changes how the date is displayed in the filter text box as the original poster mentioned which is definitely not user friendly at all. If the user is in Spanish mode they would type a date 24/10/2017 for month October day 24 of 2017 so it does not make sense to automatically change the displayed date format in the filter text box as that is just plain confusing. The MasterTableView.FilterExpression needs to be in a specified format that matches the database format such as US format in my case for custom filtering.

    Where can we modify the date for the filter expression to be in line with the database format?

  4. Ryan
    Ryan avatar
    39 posts
    Member since:
    Jun 2016

    Posted 18 Dec 2017 in reply to Ryan Link to this post

    Whenever filtering is done by the user NeedDataSource is called for me and I use grid.MasterTableView.FilterExpression to get the filters used in SQL format and I pass it to my function to get the data for the grid based on these filters. The format of these dates needs to be in the correct format while maintaining the dates being displayed to the user in the localized format.
  5. pieriv
    pieriv avatar
    3 posts
    Member since:
    Oct 2017

    Posted 11 Jan 2018 in reply to Ryan Link to this post

    Hi Ryan,

    Did you find a solution to your problem?
    I am running into a similar issue.

     

     

  6. pieriv
    pieriv avatar
    3 posts
    Member since:
    Oct 2017

    Posted 11 Jan 2018 in reply to pieriv Link to this post

    Apparently it is not possible : https://feedback.telerik.com/Project/108/Feedback/Details/147955-filterexpression-datetime-in-custom-datetime-format
Back to Top