tags:

views:

93

answers:

3

Hi,

I am populating one DataGridView in C# windows application. I have one DataTable in which I am displaying dates which I retrieve from database. My problem is, dates that I am getting from database includes time information also. For example, Jan 2003 12:00:00 AM ;

I want to show only Jan 2003 part of that date in cells of datatable. I tried to change the culture information of current thread, but it didnt worked. Is there any other way to achieve this?

I am using MySql as my database and there I have set datatype of this column as DATE. Then also i am getting this time information. Can anyone please enlighten on this behaviour of MySql?

Thanks and Regards,

A: 

Set the Format property on your column to what is required:

// Set the Format property on the "Last Prepared" column to cause
// the DateTime to be formatted as "Month, Year".
dataGridView1.Columns["Last Prepared"].DefaultCellStyle.Format = "y";
Stuart Dunkeld
+1  A: 

If you prefer to do this at the SQL level, you can do this in your select;

select convert(varchar(max),getdate(),107) as thedate

I'd always recommend not abstracting the data and letting the datagridview doing the cosmetics however.

Chris Laythorpe
A: 

Thanks everyone. I solved my problem by changing my query. I used date_format() function of MySql which gave me exact format . Here is the link which gives more information about this function.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

Shekhar