Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am retrieving date from MS-Access database. In the database 'TDate' is in dd-MM-yy format. But when I am retrieving it for a grid, it is not showing in the correct format. I also tried to convert it into datetime, but it doesn't happen. Can somebody help me out?
C#
IFormatProvider culture = new CultureInfo("hi-IN", true);
TDate =ds.Tables["tbl_Bank_Book"].Rows[i]["TDate"].ToString();
//   dt = Convert.ToDateTime(TDate,culture);
//  DateTime t = DateTime.Parse(TDate, culture);
//  dt = DateTime.ParseExact(TDate, "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault);
Posted
Updated 20-Jan-11 0:37am
v2
Comments
justinonday 20-Jan-11 6:46am    
TDate =ds.Tables["tbl_Bank_Book"].Rows[i]["TDate"].ToString("dd/MM/yyyy");
arshad alam 20-Jan-11 7:27am    
i am getting compile exception, ToString() method cannt be overloaded.

have you checked ever??

You do not say if this is a WinForms or ASP/WebForm application and simply referring to a 'grid' only confuses things more as there are several varieties of 'grid'.

If it is WinForms and you do actually mean a DataGridView, then this[^] example of using the CellFormatting event to modify data for display might be useful. It even gives an example for Dates.
 
Share this answer
 
Checkout the DateTime.ParseExact method:

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx[^]

EDIT============

I don't know why this was down-voted. ParseExact will address his problem.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 20-Jan-11 13:12pm    
Yes, it should. I up-voted 5.
Hemraj Gujar 21-Jan-11 5:31am    
perfect
This[^] might help.
 
Share this answer
 
Comments
Blesson Mathew 20-Jan-11 6:41am    
Good direction so 5+
Henry Minute 20-Jan-11 10:46am    
Excellent link! + 5
Thank you all who replied for my question but i did in in this way....

private void button1_Click(object sender, EventArgs e)
{
DateTime theDate = DateTime.Parse(dateTimePicker1.Value.ToString());
MessageBox.Show( MyFormatting1(theDate));
}

private string MyFormatting1(DateTime dt)
{
StringBuilder dateString = new StringBuilder();
dateString.Append(dt.Day);
dateString.Append("-");
dateString.Append(dt.Month);
dateString.Append("-");
dateString.Append(dt.Year.ToString());
return dateString.ToString();
}

Thank you,
Arshad
 
Share this answer
 

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