473,800 Members | 2,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:BoundColum n HeaderText="Dat e" DataField="Inse rtDate"
SortExpression= "InsertDate " ItemStyle-Width="150" />

Thanks
Kenneth
Nov 18 '05 #1
2 2666
Hi

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

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

regards,
Kannan

"Kenneth Keeley" <ke*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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:BoundColum n HeaderText="Dat e" DataField="Inse rtDate"
SortExpression= "InsertDate " ItemStyle-Width="150" />

Thanks
Kenneth

Nov 18 '05 #2
Hi,

Set the DataFormatStrin g property to whichever format you need. See the
BoundColumn.Dat aFormatString 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:BoundColum n HeaderText="Dat e" DataField="Inse rtDate"
DataFormatStrin g="{0:ddd, dd MMM yyyy, HH:mm}"
SortExpression= "InsertDate " ItemStyle-Width="150" />

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

Tue, 12 Oct 2004, 12:55

Hope this helps
Martin
"Kenneth Keeley" <ke*******@hotm ail.com> wrote in message
news:#x******** ******@TK2MSFTN GP11.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:BoundColum n HeaderText="Dat e" DataField="Inse rtDate"
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
7804
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 display the date AND the time, I don't need nor want the time just the date. If I format at any point to a ShortDate I have to convert the type to a string which when applied to the grid interferes with sorting. Is there any way to keep the...
7
7675
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 'mm/dd/yyyy' in stead of '04/10/2001'. I know I didn't do it right. Please let me know what's the correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn. Thanks.
1
2316
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 and Currency format, all others are strings. I'd like to build one datagrid to handle this datagrid dynamically. I have it working now, all except the formatting of the 5th (Date) and 6th (Currency) columns. Since the headers for those...
2
1561
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"> <columns> <asp:BoundColumn DataField="RegionalID" /> <asp:BoundColumn DataField="StartDate" DataFormatString="{d}" /> </columns>
10
2204
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 don´t want that. 2nd Example: Field in BD: DtSegm 17-02-2004
4
2070
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 started doing a RTRIM(date) when I was retrieving the data. That screwed the pooch big time. Suddenly I lost
1
282
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 want to see exactly how it is in my table. How do i accomplish that with .NET so it does not change the format
4
9637
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 '07-Mar-05' the expression {..:dd-MMM-yy} works OK Second question, does anyone know hwo to return a date from SQL server in the format '07-Mar-05', as this would be a workaround. At the moment I'm using CONVERT(varchar(12),columnname,6 ) to...
2
6486
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() myGridTextBoxColumn = CType(datagrid.TableStyles (0).GridColumnStyles("StartDate"), DataGridTextBoxColumn) myGridTextBoxColumn.Format="hh:mm:ss tt"
1
1623
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 in the format DD/MM/YYYY ? I have tried colDateCompleted.DataFormatString = "{0:d}" but this still displays the whole date including the time.
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10269
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.