473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Format Date in a DataGrid

Hi,
I am reading in results from an SQL database one of the fields is a date
value. I wish to be able to display the date as only "dd/mm/yyyy" can some
body give me an example. Here is the code I am using at the moment.

<asp:BoundColumn HeaderText="Date" DataField="InsertDate"
SortExpression="InsertDate" ItemStyle-Width="150" />

Thanks
Kenneth
Nov 18 '05 #1
2 2654
Hi

In the item data bound event,
e.Item.Cells[6].Text =
Convert.ToDateTime(e.Item.Cells[6].Text).ToString("dd-MM-yyyy");

instead of 6 change it your column number....

regards,
Kannan

"Kenneth Keeley" <ke*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I am reading in results from an SQL database one of the fields is a date
value. I wish to be able to display the date as only "dd/mm/yyyy" can some
body give me an example. Here is the code I am using at the moment.

<asp:BoundColumn HeaderText="Date" DataField="InsertDate"
SortExpression="InsertDate" ItemStyle-Width="150" />

Thanks
Kenneth

Nov 18 '05 #2
Hi,

Set the DataFormatString property to whichever format you need. See the
BoundColumn.DataFormatString property topic for details:

http://msdn.microsoft.com/library/en...tringTopic.asp

See Formatting Overview (specifically the link to "Custom DateTime format
strings") to get more info on formatting:

http://msdn.microsoft.com/library/en...ngoverview.asp

Example:

<asp:BoundColumn HeaderText="Date" DataField="InsertDate"
DataFormatString="{0:ddd, dd MMM yyyy, HH:mm}"
SortExpression="InsertDate" ItemStyle-Width="150" />

for today, supposing the Thread.CurrentCulture is "en-??" will display

Tue, 12 Oct 2004, 12:55

Hope this helps
Martin
"Kenneth Keeley" <ke*******@hotmail.com> wrote in message
news:#x**************@TK2MSFTNGP11.phx.gbl...
Hi,
I am reading in results from an SQL database one of the fields is a date
value. I wish to be able to display the date as only "dd/mm/yyyy" can some
body give me an example. Here is the code I am using at the moment.

<asp:BoundColumn HeaderText="Date" DataField="InsertDate"
SortExpression="InsertDate" ItemStyle-Width="150" />

Thanks
Kenneth

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: A Programmer | last post by:
I can't believe I have never run into this before but, I have an object that has a property of type DateTime. A collection of these objects are used to populate my DataGrid. In DateTime format they...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
2
by: Wayne Wengert | last post by:
I want to format a date field in a DataGrid column as mm/dd/yyyy. I am using the following code: <asp:DataGrid id="DataGrid1" AutoGenerateColumns="false" EnableViewState="False" runat="server">...
10
by: ruca | last post by:
Hi I want to format some columns of my DataGrid control. Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I...
4
by: Paul | last post by:
Hi, Everything went fine getting a short date format out of SQL into my DataGrid with this: <%# DataBinder.Eval(Container.DataItem, "Created", "{0:d}")%> Then I got too fancy in SQL and...
1
by: Mike | last post by:
I have a date in my table format like YYYY/DD/MM 2004/7/7 but when I pull that value out of the table in .net and populate my grid it looks like: 7/7/2004 12:00:00 AM I don't want that, i...
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
2
by: Sebastian Santacroce | last post by:
I'm trying to format datetime column in datagrid to a time format rather than date. I'm using code: Dim myGridTextBoxColumn As DataGridTextBoxColumn = New DataGridTextBoxColumn() ...
1
by: Niclas Lindblom | last post by:
Hi, I have a bound column in a datagrid. The value in the database is using the SQL datetime format which gives both date and time. How do I configure the datagrid cell to only display the date...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.