datetime format in asp.net

Posted by Dn2010 under ASP.NET on 4/4/2012 | Points: 10 | Views : 1427 | Status : [Member] | Replies : 7
hi friends,

now display in Label1 date in this format

4/3/2012 10:44:42 PM

but

i want to display like this in label1 from database

2012-04-03 22:44:42.000


OpenConnection(con);
cmd.Connection = con;

SqlDataAdapter da = new SqlDataAdapter("select top 1 calldate from data", con);
DataTable dt = new DataTable();
da.Fill(dt);

if (dt.Rows.Count > 0)
{
Label1.Text = dt.Rows[0][0].ToString();

}
else
{
Label1.Text = "No Records found!";
}
con.Close();





please give the code for it,


thanks.




Responses

Posted by: Rimjhim4 on: 4/4/2012 [Member] Starter | Points: 25

Up
0
Down
select top 1 convert(VARCHAR, calldate, 21) from data...................
try this.............

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Leila on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
try this
Label1.Text = dt.Rows[0][0].ToString("yyyy-MM-dd HH:mm:ss.fff"); 


Thanks,
Leila

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Denny on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
Try this format

SELECT convert(varchar, getdate(), 21)

Regards,
Denny Kurian

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
u can follow leila's code it is correct.

Thanks&Regards
Hari

Thanks & Regards
Hari

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/13/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Refer This Link

http://www.dotnetfunda.com/codes/code2224-given-date-to-change-the-date-formate.aspx

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/13/2012 [Member] Bronze | Points: 25

Up
0
Down
HI ...

If You Feel as a Answer


MARK AS ANSWER....

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/8/2012 [Member] Starter | Points: 25

Up
0
Down
Label1.Text = dt.Rows[0][0].ToString("yyyy-MM-dd HH:mm:ss.fff");

it work for me

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response