Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
 
How do I remove ':' from Time format that I retrieve from database.
 
My code:
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 30-Nov-12 22:12pm
Ash29470
Edited 30-Nov-12 22:15pm
v3
Comments
André Kraak at 1-Dec-12 3:17am
   
What is the output you are looking for?
Are you expecting 113036?
Ash29 at 1-Dec-12 3:24am
   
yes exactly
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try using the Replace method[^]:
string time1 = T.TimeOfDay.ToString().Replace( ":", "" );
  Permalink  
Comments
__TR__ at 1-Dec-12 3:33am
   
My 5!
André Kraak at 1-Dec-12 3:34am
   
Thanks :)
Ash29 at 1-Dec-12 3:40am
   
Thanks for the reply.
This solution is efficient enough.
André Kraak at 1-Dec-12 3:41am
   
Your welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

hi,
check this
string time1 = T.TimeOfDay.ToString("HHmmss")
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

string time1 = T.TimeOfDay.ToString().Split(':')[0].ToString();
but it'll output like this only: 11
  Permalink  
v2
Comments
Ash29 at 1-Dec-12 3:18am
   
Thanks.
that works!
Ash29 at 1-Dec-12 3:19am
   
A quick n prompt reply
CodeProject simply rockz
Krunal R at 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)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100