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

How to change datetime format in FilterExpression?

5 Answers 307 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 09 Aug 2013, 04:34 AM
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?

5 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 13 Aug 2013, 12:26 PM
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.
0
Ryan
Top achievements
Rank 1
answered on 19 Dec 2017, 12:25 AM

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?

0
Ryan
Top achievements
Rank 1
answered on 19 Dec 2017, 12:38 AM
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.
0
Pierre-Yves
Top achievements
Rank 1
answered on 11 Jan 2018, 02:00 PM

Hi Ryan,

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

 

 

0
Pierre-Yves
Top achievements
Rank 1
answered on 11 Jan 2018, 02:05 PM
Apparently it is not possible : https://feedback.telerik.com/Project/108/Feedback/Details/147955-filterexpression-datetime-in-custom-datetime-format
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Ryan
Top achievements
Rank 1
Pierre-Yves
Top achievements
Rank 1
Share this question
or