Posted by: Draško Sarić | June 19, 2007

Formatting a datetime column in ASP.NET

By default, when you start wizard for creating GridView or DetailsView, and you have datetime field you will get date shown with time , which in most cases you don’t need. In my experience, I mostly needed date or time shown separately. In this short article I will show you how you can display date (only) in these controls. The same thing can be applied to TextBox, too.

Anyways, you choose “Edit Fields” in dropdown menu that can be accessed by clicking on little right-oriented arrow located on upper rigth corner of control. In Selected fields, locate the field you wish to adjust and click on it. On right side of window (BoundField properties), find section Data and under this section find DataFormatString. Here you can define format in which you can show your date in following manner, for example: {0:MM/dd/yyyy}. This 0 symbol is “zero”. If you wish to apply this format in Edit Mode, locate under Behavior section property ApplyFormatInEditMode and enter True value.

Depending of date format you need, you can choose Standard DateTime Format Strings, or Custom DateTime Format Strings.

If this doesn’t work, set parameter HtmlEncode to False.

And that’s it.

Make money with this. 🙂



  1. Awsome article!!!!!!!!!!!!

  2. Thanks!

  3. Tahanks A lot !! It Works

  4. Thank you. It works when i set HTMLEncode to False . Love you ^^

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


%d bloggers like this: