Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • When binding a DateTime? property to an AspxGridView and attempting to display it in a GridViewDataDateColumn, no DisplayFormatString formatting commands are used.
                                    This has brought to our attention as within our property, we have a 24 hour time stored (16:00) - when displayed in the grid however it is shown as 04:00.
                                    No matter what DisplayFormatString we tried to apply, the format of the data displayed in the column did not change at all.
                                    The only difference between this and other displayed DateTime values in our project is that this particular property is a nullable DataTime (DateTime?).

                                    Steps to Reproduce:

                                    Databind a datasource that contains a DateTime? to a AspcGridView.

                                    Attempt to display this value in a GridViewDataDateColumn.

                                    (Ensure one of the time's in the DateTime is 16:00).

                                    Attempt to get the time to display in 24 hour format.

                                    e.g. using: <PropertiesDateEdit DisplayFormatString="dd MMM yyyy HH:mm:ss"></PropertiesDateEdit>

                                    example of the GridViewDataDateColumn declaration in aspx page:

                                    <dxwgv:GridViewDataDateColumn Caption="Date/Time" FieldName="MyDatetime" VisibleIndex="0">

                                         <PropertiesDateEdit DisplayFormatString="dd MMM yyyy HH:mm:ss"></PropertiesDateEdit>

                                         <CellStyle HorizontalAlign="Center">

                                         </CellStyle>

                                    </dxwgv:GridViewDataDateColumn>

                                    The FieldName "MyDatetime" is declared a DateTime? (nullable DateTime) in an object dataset which is databound to the grid.

                                    Actual Results:

                                    The time element will always be displayed in 12 hour format and will invaribaly knock 12 hours off the time

                                    e.g. time of 16:00 will be displayed as 04:00

                                    Expected Results:

                                    The time element should show either in 24 hour format, or with the correct AM/PM suffix.

                                    e.g 16:00 should be displayed as "16:00" or 4 PM

                                0

                                Hi Thomas,

                                Thank you for the report. It seems that this is not our issue. Please try to use the following code in the Page_Load method and check the text's value in the debugger:

                                string text = string.Format(System.Threading.Thread.CurrentThread.CurrentCulture, "{0:G}", new DateTime(2009, 05, 11, 16, 00, 00));

                                What are your results?

                                Thanks,
                                Plato

                                0

                                Hi Plato,

                                Thank you for the reply.
                                I tried the code supplied by yourselves in the Page_Load event of the page.
                                The results in the text string were: "11/05/2009 16:00:00".

                                However, the format string of "G" was only given as example, to illustrate that we were using the <PropertiesDateEdit> tag within the column. The issue is with nullable DateTimes (DateTime? not DateTime).
                                Using DateTime databound types within the grid from an object dataset will format the Date and Time correctly using the specified DisplayFormatString. However, whenever we try to use DisplayFormatString on a databound nullable DateTime column (DateTime?) the formatting is ignored, and the results will always be in a 12 hour format.

                                Please try and use the format:"dd MMM yyyy HH:mm:ss" for the time of 16:00, but assign this to a nullable DateTime instance, and this will display as 04:00 and ignore all formatting specified.

                                Thanks

                                Barry

                                0

                                Hi Thomas,

                                Here is my sample project, which seems to work properly here. I have set the UK locale on my machine, and both ASPxGridView and my code works the same. What are your results?

                                Thanks,
                                Plato

                                dxSample.zip
                                0

                                Hi Plato,

                                Thank you for your assistance.
                                Your example solution worked perfectly, and so we went through various iterations trying to replace the grid we were using in our solution with the simple one you provided and even had your example grid displaying elements from our business objects - but nothing was recreating the error we saw on this one page.

                                In the end, frustratingly, we discovered some server-side code that was manually setting the date format of the column in the grid.
                                We removed this and everything worked as expected.

                                Thanks for all of yout assistance with this.

                                Regards

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners