Click here to Skip to main content
15,868,128 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How do I remove ':' from Time format that I retrieve from database.

My code:
C#
int rowcount = dataGridView1.Rows.Count;
for (int i = 0; i < rowcount; i++)
{
    DateTime T = DateTime.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
    string time1 = T.TimeOfDay.ToString();
    sw.WriteLine(time1);
}

My Output - 11:30:36
Posted
Updated 30-Nov-12 21:15pm
v3
Comments
André Kraak 1-Dec-12 3:17am    
What is the output you are looking for?
Are you expecting 113036?
Ash29 1-Dec-12 3:24am    
yes exactly

Try using the Replace method[^]:
C#
string time1 = T.TimeOfDay.ToString().Replace( ":", "" );
 
Share this answer
 
Comments
__TR__ 1-Dec-12 3:33am    
My 5!
André Kraak 1-Dec-12 3:34am    
Thanks :)
Ash29 1-Dec-12 3:40am    
Thanks for the reply.
This solution is efficient enough.
André Kraak 1-Dec-12 3:41am    
Your welcome.
hi,
check this
string time1 = T.TimeOfDay.ToString("HHmmss")
 
Share this answer
 
C#
string time1 = T.TimeOfDay.ToString().Split(':')[0].ToString();

but it'll output like this only: 11
 
Share this answer
 
v2
Comments
Ash29 1-Dec-12 3:18am    
Thanks.
that works!
Ash29 1-Dec-12 3:19am    
A quick n prompt reply
CodeProject simply rockz
[no name] 1-Dec-12 3:24am    
Yeah :)

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