Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:

Hi all,

I have a DataGridView control and its DataSource property is bound to a table received from an MS-SQL query. All of the data types in the bound table are smalldatetime. 

After I receive the table, I want to display the data as "dd-mm-yyyy" rather than "mm-dd-yyyy".

Any suggestions?

Thanks.

Posted
Updated 6-Jul-20 18:54pm
v2

Add Dataformatstring="dd-MM-yyyy" in bound field column
 
Share this answer
 
Perhaps Googling on  String.Format() would give you an idea?
 
Share this answer
 
CSS
You can try this:
dataGridView1.Columns[0].DefaultCellStyle.Format = "dd/MM/yyyy";
Hope this will help you.
 
Share this answer
 
Comments
Tamil Arasu K 19-Jul-14 8:15am    
in my grid have some null values in date field at that time this format is not working... how can i resolve this problem?

thx 4 ur help guys!

eventually i used: 

c[column_index].DefaultCellStyle.Format = "dd-MM-yyyy";   

for each column i wanted to format.

 thx again!!! 

 
Share this answer
 
This can help

Dim xRowCount As Integer = 0
Do Until xRowCount = xDataGrid.RowCount
xDataGrid.Rows(xRowCount).Cells(2).Style.Format = Format("dd-MMM-yyyy")
xRowCount = xRowCount + 1
Loop
 
Share this answer
 
Comments
CHill60 5-Jun-14 4:39am    
You do realise that the OP posted the solution they used over 4 and a half years ago!
For SQL Convert(varchar(20), ColumnName, 20) AS ColumnSameName

I use this to import data to a datagridview in c# format the date at query and display the datetime

Then I get that information and export to a CSV - Otherwise the format will show dd/mm/yyyy HH:mm tt

Result:

yyyy-MM-dd HH:mm:ss

2014-11-21 02:03:04
 
Share this answer
 
Comments
CHill60 22-Nov-14 7:18am    
You're trying to answer a 5 year old question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900