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

GridViewDateTimeColumn formatString

6 Answers 900 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gerbrand
Top achievements
Rank 2
gerbrand asked on 16 Apr 2009, 09:20 AM
Hi,

Maybe a stupid question, but I was wondering if there is an overview of the different formatstrings you can use for the DateTime Column?

I want to make a static function where I just need to call the right formatString, instead of every time searching the "net" for the right syntacs and add it.

Thanks

6 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 17 Apr 2009, 12:20 PM
Hello Gerbrand,

These are some samples of formatting DateTime column in RadGridView:

GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];  
column.DataTextFormatString = "{0:hh.mm.ss}";  //hour.minutes.seconds 
column.DataTextFormatString = "{0:dd.MM.yy}";  //day.month.year 
column.DataTextFormatString = "{0:hh.mm}";      //hour.minutes 
column.DataTextFormatString = "{0:dd.MMMM.yy}";  //day.long month name.year 
column.DataTextFormatString = "{0:dd-MM-yy}";  //day-month-year 
 

You can find more information for DateTime formatting in MSDN.

Greetings,
Julian Benkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
tuonglam
Top achievements
Rank 1
answered on 09 Sep 2011, 10:20 AM
I'm using like you say but i have a error.I'm using in Formload

'Telerik.WinControls.UI.GridViewDateTimeColumn' does not contain a definition for 'DataTextFormatString' and no extension method 'DataTextFormatString' accepting a first argument of type 'Telerik.WinControls.UI.GridViewDateTimeColumn' could be found (are you missing a using directive or an assembly reference?)

My code:

GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];
 column.DataTextFormatString = "{dd-MM-yy}";  //day-month-year

thank you very much!
0
Nikolay
Telerik team
answered on 14 Sep 2011, 09:27 AM
Hi Tuonglam,

The code snippet provided by my colleague Julian concerned a version of RadControls for WinForms issued during 2009. If you are using one of the latest versions, you have to use the FormatString property as shown below:

GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];
column.FormatString = "{0:hh.mm.ss}"//hour.minutes.seconds
column.FormatString = "{0:dd.MM.yy}"//day.month.year
column.FormatString = "{0:hh.mm}";      //hour.minutes
column.FormatString = "{0:dd.MMMM.yy}"//day.long month name.year
column.FormatString = "{0:dd-MM-yy}"//day-month-year

I hope this helps.

Greetings,
Nikolay
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Scott
Top achievements
Rank 1
answered on 10 Feb 2017, 10:22 PM

How does this work if the SQL Server datatype is TimeSpan?

Thank you.

-Scott

0
Dimitar
Telerik team
answered on 13 Feb 2017, 03:57 PM
Hi Scott,

By default, the grid will create a GridViewTextBoxColumn, but you can replace the default text editor with the desired one in the EditorRequired event. Note that if the applied editor is not compatible with the TimeSpan value, it would be necessary to implement a Type Converter. A sample approach is demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types

In addition, we have a feature request for this in our Feedback Portal. I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comment to it here.

I hope this information is useful. Let me know if you need further assistance.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Scott
Top achievements
Rank 1
answered on 13 Feb 2017, 04:10 PM

Hi Dimitar-

Thank you for the feature up vote and the interim guidance.

-Scott

Tags
GridView
Asked by
gerbrand
Top achievements
Rank 2
Answers by
Julian Benkov
Telerik team
tuonglam
Top achievements
Rank 1
Nikolay
Telerik team
Scott
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or