Skip to content
March 10, 2008 / kiranpatils

Formatting Date and Time in GridView

Today, I am playing with Gridview and have to show data in it from SQL SERVER 2005. it has a field called as “JoiningDate” bounded with column “JoiningDate”. it was working fine it was showing date in the format like this: 2007-11-27 10:00:00.000 but i want to show it like this “11 Dec 2007”. I found it from MSDN. so here it is!!

Old Code[O/P=2007-11-27 10:00:00.000]:

<asp:BoundField DataField=”JoiningDate” HeaderText=”JoiningDate” / >

New one [O/P = 11 Dec 2007]

<asp:BoundField DataField=”JoiningDate” HeaderText=”JoiningDate” DataFormatString=”{0:dd MMM yyyy}” HtmlEncode=”False”/ >


Two main tags helped me too achieve this:

1. DataFormatString: you can specify format to display string.

dd = Date

MMM = Month

yyyy = year

2. HtmlEncode: the field are HTML Encoded before they shown to bound field.Default true

NOTE: if you don’t do HTMLEncode=”False” .it won’t work. Because default it true.


Hope it will help you too as it helped me..


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: