Formatting a time to show zero hours in a GridBoundColumn

I had an issue where the time inside a Telerik GridBoundColumn control was displaying the incorrect time. The value from the database was correct, and was 3/6/2011 00:00. However, in the control, the value was being displayed at 3/6/2011 12:00. That’s, like, twelve hours off! That’s no good.

The issue was the DataFormatString value of the GridBoundColumn. It was set to {0}. Instead, I changed it to:

{0:M/d/yyyy HH:mm}

This explicitly set the time, and the value was then showing correctly as 3/6/2011 00:00.

BTW, the final GridBoundColumn definition looked like this:

<telerik:GridBoundColumn UniqueName="LastUpdateDate" DataField="LastUpdateDate" 
DataFormatString="{0:M/d/yyyy HH:mm}"></telerik:GridBoundColumn>
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: