Home » VB.NetRSS

How to show only date in DataColumn of Datatable?

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,

 

8 Answers Found

 

Answer 1

I Solved the problem. Used date_format() function of MySql. It works perfectly.

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

 

Answer 2

Hi Chandrashekhar,

it can be done by formating check this link for detail

http://stackoverflow.com/questions/3156862/how-to-show-only-date-in-datacolumn-of-datatable

regards,

 

Answer 3

when you populate column of dataGridView do the following:

dataGridView1.Rows[row].Cells[column].Value = Convert.ToDateTime(dr["DateColumn"]).ToString("MM.yyyy");

 

Answer 4

dataGridView1.Columns[column].DefaultCellStyle.Format = "MMM yyyy";
 

Answer 5

Hi shekhar9448,

   Welcome to MSDN forums! I'm glad to see your active participation and discussion in MSDN forums. Based on your issue I'll suggest you 2 good choice.

  1. Use mysql date  function to convert after fill date in datatable. (please refer to http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format)

  2. Use DataGridView cell format (http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/bb5ef524-b2ba-4420-82ac-230d156695aa/)

Hope this will help you!  

   If you still have any doubt and concern about this issue, please let me know. If I misunderstood you, please kindly elaborate your question.

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information  as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


Please Mark as Answered If this is helpful Or Un-Mark as Answered if it is not helpful.

Best Regards,
Yan Jun
Microsoft Online Community Support

 

Answer 6

Thanks Yan Jun for help.

I have solved the problem  by using MySql date_format() function.


Thanks and Regards, Chandrashekhar
 

Answer 7

 

 

 

hey killer,

thats my post on stackoverflow :)

thanks for help.

 

Answer 8

Hi Shekhar9448,

  You are welcome I'm pleased it helped

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter